@@ -7,10 +7,91 @@ const colorArgs = custom.colorArgs
7
7
8
8
const cat = 'Instance Methods/Lifecycle'
9
9
10
- const VM_$MOUNT = { }
11
- const VM_$FORCE_UPDATE = { }
12
- const VM_$NEXT_TICK = { }
13
- const VM_$DESTROY = { }
10
+ const VM_$MOUNT = {
11
+ category : cat ,
12
+ name : `vm.$mount([elementOrSelector])` ,
13
+ arguments : [
14
+ `{Element | string} [elementOrSelector]` ,
15
+ `{boolean} [hydrating]` ,
16
+ ] ,
17
+ returns : `vm - the instance itself` ,
18
+ usage : `If a Vue instance didn’t receive the ${ colorArgs ( `el` ) } option at instantiation,
19
+ it will be in “unmounted” state, without an associated DOM element.
20
+ ${ colorArgs ( `vm.$mount()` ) } can be used to manually start the mounting of
21
+ an unmounted Vue instance. If ${ colorArgs ( `elementOrSelector` ) } argument
22
+ is not provided, the template will be rendered as an off-document
23
+ element, and you will have to use native DOM API to insert it
24
+ into the document yourself. The method returns the instance itself
25
+ so you can chain other instance methods after it.` ,
26
+ example : `
27
+ ${ colorArgs ( `var` ) } MyComponent = Vue.extend({
28
+ template: ${ chalk . green ( "'<div>Hello!</div>'" ) }
29
+ })
30
+ ${ colorComment ( `// create and mount to #app (will replace #app)` ) }
31
+ ${ colorArgs ( `new` ) } MyComponent().$mount(${ chalk . green ( "'#app'" ) } )
32
+ ${ colorComment ( `// the above is the same as:` ) }
33
+ ${ colorArgs ( `new` ) } MyComponent({ el: '#app' })
34
+ ${ colorComment ( `// or, render off-document and append afterwards:` ) }
35
+ ${ colorArgs ( `var` ) } component = ${ colorArgs ( `new` ) } MyComponent().$mount()
36
+ ${ chalk . green ( "document" ) } .getElementById(${ chalk . green ( "'app'" ) } ).appendChild(component.$el)
37
+ `
38
+ }
39
+
40
+ const VM_$FORCE_UPDATE = {
41
+ category : cat ,
42
+ name : `vm.$forceUpdate()` ,
43
+ usage : `Force the Vue instance to re-render. Note it does not affect all
44
+ child components, only the instance itself and child components
45
+ with inserted slot content.`
46
+ }
47
+
48
+ const VM_$NEXT_TICK = {
49
+ category : cat ,
50
+ name : `vm.$nextTick([callback])` ,
51
+ arguments : [
52
+ `{Function} [callback]`
53
+ ] ,
54
+ usage :`Defer the callback to be executed after the next DOM update
55
+ cycle. Use it immediately after you’ve changed some data to wait
56
+ for the DOM update. This is the same as the global ${ colorArgs ( `Vue.nextTick` ) } ,
57
+ except that the callback’s ${ colorArgs ( `this` ) } context is automatically bound
58
+ to the instance calling this method.
59
+ ${ chalk . bold ( `New in 2.1.0: returns a Promise if no callback is provided and
60
+ Promise is supported in the execution environment` ) } .
61
+
62
+ ` ,
63
+ example : `
64
+ ${ colorArgs ( `new` ) } Vue({
65
+ ${ colorComment ( `// ...` ) }
66
+ methods: {
67
+ ${ colorComment ( `// ...` ) }
68
+ example: ${ chalk . blue ( `function` ) } () {
69
+ ${ colorComment ( `// modify data` ) }
70
+ ${ colorArgs ( `this` ) } .message = 'changed'
71
+ ${ colorComment ( `// DOM is not updated yet` ) }
72
+ ${ colorArgs ( `this` ) } .$nextTick(${ chalk . blue ( `function` ) } () {
73
+ ${ colorComment ( `// DOM is now updated` ) }
74
+ ${ colorComment ( `// 'this' is bound to the current instance` ) }
75
+ ${ colorArgs ( `this` ) } .doSomethingElse()
76
+ })
77
+ }
78
+ }
79
+ })
80
+
81
+ `
82
+ }
83
+
84
+ const VM_$DESTROY = {
85
+ category : cat ,
86
+ name : `vm.$destroy()` ,
87
+ usage : `Completely destroy a vm. Clean up its connections with other existing vms,
88
+ unbind all its directives, turn off all event listeners.
89
+ Triggers the ${ colorArgs ( `beforeDestroy` ) } and ${ colorArgs ( `destroyed` ) } hooks.
90
+
91
+ In normal use cases you shouldn’t have to call this method yourself.
92
+ Prefer controlling the lifecycle of child components in a data-driven
93
+ fashion using ${ colorArgs ( `v-if` ) } and ${ colorArgs ( `v-for.` ) } .`
94
+ }
14
95
15
96
module . exports = {
16
97
VM_$MOUNT,
0 commit comments