@@ -29,23 +29,66 @@ const VM_$WATCH = {
29
29
because they reference the same Object/Array.
30
30
Vue doesn’t keep a copy of the pre-mutate value.` ,
31
31
example : `
32
- // keypath
33
- vm.$watch('a.b.c', function (newVal, oldVal) {
34
- // do something
32
+ ${ colorComment ( ` // keypath` ) }
33
+ vm.$watch(${ chalk . green ( ` 'a.b.c'` ) } , ${ chalk . blue ( ` function` ) } (newVal, oldVal) {
34
+ ${ colorComment ( ` // do something` ) }
35
35
})
36
- // function
36
+ ${ colorComment ( ` // function` ) }
37
37
vm.$watch(
38
38
function () {
39
39
return this.a + this.b
40
40
},
41
41
function (newVal, oldVal) {
42
- // do something
42
+ ${ colorComment ( ` // do something` ) }
43
43
}
44
44
)
45
+ ${ colorArgs ( `vm.$watch` ) } returns an unwatch function that stops firing the callback:
46
+ ${ colorArgs ( `var` ) } unwatch = vm.$watch(${ chalk . green ( `'a'` ) } , cb)
47
+ ${ colorComment ( `// later, teardown the watcher` ) }
48
+ unwatch()
49
+
50
+ * ${ chalk . bold ( `Option: deep` ) }
51
+ To also detect nested value changes inside Objects, you need to pass in ${ colorArgs ( 'deep: true' ) } in the
52
+ options argument.
53
+ Note that you don’t need to do so to listen for Array mutations.
54
+
55
+ vm.$watch(${ chalk . green ( `'someObject'` ) } , callback, {
56
+ deep: ${ colorPrimitive ( `true` ) }
57
+ })
58
+ vm.someObject.nestedValue = ${ colorPrimitive ( `123` ) }
59
+ ${ colorComment ( `// callback is fired` ) }
60
+
61
+ * ${ chalk . bold ( `Option: immediate` ) }
62
+ Passing in ${ colorArgs ( `immediate: true` ) } in the option will trigger the callback immediately
63
+ with the current value of the expression:
64
+ vm.$watch(${ chalk . green ( `'a'` ) } , callback, {
65
+ immediate: ${ colorPrimitive ( `true` ) }
66
+ })
67
+ ${ colorComment ( `// callback is fired immediately with current value of 'a'` ) }
45
68
`
46
69
}
47
- const VM_$SET = { }
48
- const VM_$DELETE = { }
70
+ const VM_$SET = {
71
+ category : cat ,
72
+ name : 'vm.$set(target,key,value)' ,
73
+ arguments : [
74
+ `{Object | Array) target` ,
75
+ `{string | number} key` ,
76
+ `{any} value`
77
+ ] ,
78
+ returns : `the set value.` ,
79
+ usage : `This is the ${ chalk . bold ( `alias` ) } of the global ${ colorArgs ( `Vue.set` ) } .`
80
+ }
81
+
82
+ const VM_$DELETE = {
83
+ category : cat ,
84
+ name : `vm.$delete(target,key)` ,
85
+ arguments :[
86
+ `{Object | Array} target` ,
87
+ `{string | number} key`
88
+ ] ,
89
+ usage : `This is the ${ chalk . bold ( `alias` ) } of the global ${ colorArgs ( `Vue.delete` ) } .`
90
+
91
+ }
49
92
50
93
module . exports = {
51
94
VM_$WATCH,
0 commit comments