Skip to content

Commit 9f55493

Browse files
committed
vmodel,test,docs
1 parent 51d44e0 commit 9f55493

18 files changed

+387
-3
lines changed

docs/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
- [Property](class-component/property/property.md)
66
- [Method](class-component/method/method.md)
77
- [Lifecycle hooks](class-component/lifecycle-hook/lifecycle-hook.md)
8+
- [Component property](class-component/component-property/component-property.md)
89
- [Getter](class-component/getter/getter.md)
910
- [Event](class-component/event/event.md)
1011
- [Reference](class-component/reference/reference.md)
1112
- [Watcher](class-component/watcher/watcher.md)
1213
- [Injection](class-component/injection/injection.md)
14+
- [VModel](class-component/v-model/v-model.md)
1315
- Inheritance
1416
- [ECMAScript class](inheritance/es-class/es-class.md)
1517
- [Component](inheritance/component/component.md)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import { Prop, Component, Vue } from 'vue-facing-decorator'
3+
4+
/*
5+
6+
Vue option component
7+
{
8+
props:{
9+
p:{
10+
default: 'foo'
11+
}
12+
}
13+
}
14+
*/
15+
16+
@Component
17+
export default class MyComponent extends Vue {
18+
@Prop({
19+
default: 'foo'
20+
})
21+
p!: string
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import { Prop, Component, Vue } from 'vue-facing-decorator'
3+
4+
/*
5+
6+
Vue option component
7+
{
8+
props:{
9+
p:{
10+
required:true
11+
}
12+
}
13+
}
14+
*/
15+
16+
@Component
17+
export default class MyComponent extends Vue {
18+
@Prop({
19+
required: true
20+
})
21+
p!: string
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import { Prop, Component, Vue } from 'vue-facing-decorator'
3+
4+
/*
5+
6+
Vue option component
7+
{
8+
props:{
9+
p:{
10+
type: String
11+
}
12+
}
13+
}
14+
*/
15+
16+
@Component
17+
export default class MyComponent extends Vue {
18+
@Prop({
19+
type: String
20+
})
21+
p!: string
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
import { Prop, Component, Vue } from 'vue-facing-decorator'
3+
4+
/*
5+
6+
Vue option component
7+
{
8+
props:{
9+
p:{
10+
validator(val:any){
11+
return true
12+
}
13+
}
14+
}
15+
}
16+
*/
17+
18+
@Component
19+
export default class MyComponent extends Vue {
20+
@Prop({
21+
validator(val:any){
22+
return true
23+
}
24+
})
25+
p!: string
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import { Prop, Component, Vue } from 'vue-facing-decorator'
3+
4+
/*
5+
6+
Vue option component
7+
{
8+
props:{
9+
p:{
10+
11+
}
12+
}
13+
}
14+
*/
15+
16+
@Component
17+
export default class MyComponent extends Vue {
18+
@Prop
19+
p!: string
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Usage
2+
3+
Use `Prop` decorator to define a watcher in vue's `props`.
4+
5+
[](./code-usage.ts ':include :type=code typescript')
6+
7+
## Options
8+
9+
### default
10+
11+
This is the `default` in vue `props`.
12+
13+
[](./code-option-default.ts ':include :type=code typescript')
14+
15+
### required
16+
17+
This is the `required` in vue `props`.
18+
19+
[](./code-option-required.ts ':include :type=code typescript')
20+
21+
### type
22+
23+
This is the `type` in vue `props`.
24+
25+
[](./code-option-type.ts ':include :type=code typescript')
26+
27+
### validator
28+
29+
This is the `validator` in vue `props`.
30+
31+
[](./code-option-validator.ts ':include :type=code typescript')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { VModel, Component, Vue } from 'vue-facing-decorator'
2+
3+
/*
4+
5+
Vue option component
6+
{
7+
props:{
8+
value:{}
9+
},
10+
computed:{
11+
valueAgent:{
12+
get(){
13+
return this['value']
14+
},
15+
set(value){
16+
this.$emit('update:value',value)
17+
}
18+
}
19+
}
20+
}
21+
*/
22+
23+
/*
24+
In other components:
25+
<MyComponent v-model:value="foo"></MyComponent>
26+
*/
27+
28+
@Component
29+
export default class MyComponent extends Vue {
30+
@VModel({
31+
name: 'value'
32+
})
33+
valueAgent!: string
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { VModel, Component, Vue } from 'vue-facing-decorator'
2+
3+
/*
4+
5+
Vue option component
6+
{
7+
props:{
8+
modelValue:{
9+
type:String,
10+
default:'bar',
11+
//...
12+
}
13+
},
14+
computed:{
15+
valueAgent:{
16+
get(){
17+
return this['modelValue']
18+
},
19+
set(value){
20+
this.$emit('update:modelValue',value)
21+
}
22+
}
23+
}
24+
}
25+
26+
*/
27+
28+
/*
29+
30+
In other components:
31+
32+
<MyComponent v-model="foo"></MyComponent>
33+
34+
*/
35+
36+
@Component
37+
export default class MyComponent extends Vue {
38+
@VModel({
39+
type: String,
40+
default: 'bar',
41+
//...
42+
})
43+
valueAgent!: string
44+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { VModel, Component, Vue } from 'vue-facing-decorator'
2+
3+
/*
4+
5+
Vue option component
6+
{
7+
props:{
8+
modelValue:{}
9+
},
10+
computed:{
11+
valueAgent:{
12+
get(){
13+
return this['modelValue']
14+
},
15+
set(value){
16+
this.$emit('update:modelValue',value)
17+
}
18+
}
19+
}
20+
}
21+
22+
*/
23+
24+
/*
25+
26+
In other components:
27+
28+
<MyComponent v-model="foo"></MyComponent>
29+
30+
*/
31+
32+
@Component
33+
export default class MyComponent extends Vue {
34+
@VModel
35+
valueAgent!: string
36+
}

0 commit comments

Comments
 (0)