@@ -28,16 +28,133 @@ const VM_$EL = {
28
28
read : 'Read only' ,
29
29
details : `The root DOM element that the Vue instance is managing.`
30
30
}
31
- const VM_$OPTIONS = { }
32
- const VM_$PARENT = { }
33
- const VM_$ROOT = { }
34
- const VM_$CHILDREN = { }
35
- const VM_$SLOTS = { }
36
- const VM_$SCOPED_SLOTS = { }
37
- const VM_$REFS = { }
38
- const VM_$IS_SERVER = { }
39
- const VM_$ATTRS = { }
40
- const VM_$LISTENERS = { }
31
+ const VM_$OPTIONS = {
32
+ category : cat ,
33
+ name : 'vm.$options' ,
34
+ type : 'Object' ,
35
+ read : 'Read only' ,
36
+ details : `The instantiation options used for the current Vue instance.
37
+ This is useful when you want to include custom properties in the options:
38
+ ${ colorArgs ( 'new' ) } Vue({
39
+ customOption: ${ chalk . green ( "'foo'" ) } ,
40
+ created: ${ chalk . blue ( 'function' ) } () {
41
+ ${ chalk . green ( 'console' ) } .log(${ colorArgs ( 'this' ) } .$options.customOption) ${ colorComment ( `// -> 'foo'` ) }
42
+ }
43
+ })`
44
+ }
45
+ const VM_$PARENT = {
46
+ category : cat ,
47
+ name : `vm.$parent` ,
48
+ type : `Vue instance` ,
49
+ read : 'Read only' ,
50
+ details : `The parent instance, if the current instance has one.`
51
+ }
52
+ const VM_$ROOT = {
53
+ category : cat ,
54
+ name : `vm.$root` ,
55
+ type : `Vue instance` ,
56
+ read : `Read only` ,
57
+ details : `The root Vue instance of the current component tree.
58
+ If the current instance has no parents this value will be itself.`
59
+ }
60
+ const VM_$CHILDREN = {
61
+ category : cat ,
62
+ name : `vm.$children` ,
63
+ type : `Array<Vue instance>` ,
64
+ read : `Read only` ,
65
+ details : `The direct child components of the current instance.
66
+ ${ chalk . bold ( `Note there’s no order guarantee for ${ colorArgs ( '$children' ) } , and it is not reactive.` ) }
67
+ If you find yourself trying to use ${ colorArgs ( '$children' ) } for data binding, consider
68
+ using an Array and ${ colorArgs ( 'v-for' ) } to generate child components, and use the Array
69
+ as the source of truth.`
70
+ }
71
+ const VM_$SLOTS = {
72
+ category : cat ,
73
+ name : `vm.$slots` ,
74
+ type : `{ [name: string]: ?Array<VNode> }` ,
75
+ read : `Read only` ,
76
+ details : `Used to programmatically access content ${ chalk . green ( `distributed by slots` ) } .
77
+ Each ${ chalk . green ( 'named slot' ) } has its own corresponding
78
+ property (e.g. the contents of ${ colorArgs ( `slot="foo"` ) } will be found at
79
+ ${ colorArgs ( `vm.$slots.foo` ) } . The ${ colorArgs ( `default` ) } property contains any nodes
80
+ not included in a named slot. Accessing ${ colorArgs ( `vm.$slots` ) } is most
81
+ useful when writing a component with a ${ chalk . green ( `render function` ) } .` ,
82
+ example : `
83
+ ${ colorComment ( '// html' ) }
84
+ ${ chalk . blue ( `<blog-post>` ) }
85
+ ${ chalk . blue ( `<h1 slot=${ chalk . green ( '"header"' ) } >` ) }
86
+ About Me
87
+ ${ chalk . blue ( `</h1>` ) }
88
+ ${ chalk . blue ( `<p>` ) } Here's some page content, which will be included in vm.$slots.default,
89
+ because it's not inside a named slot. ${ chalk . blue ( `</p>` ) }
90
+ ${ chalk . blue ( `<p slot=${ chalk . green ( '"footer"' ) } >` ) }
91
+ Copyright 2016 Evan You
92
+ ${ chalk . blue ( `</p>` ) }
93
+ ${ chalk . blue ( `<p>` ) } If I have some content down here, it will
94
+ also be included in vm.$slots.default.${ chalk . blue ( `</p>` ) } .
95
+ ${ chalk . blue ( `</blog-post>` ) }
96
+ ${ colorComment ( '// JS' ) }
97
+ Vue.component(${ chalk . green ( `'blog-post'` ) } , {
98
+ render: ${ chalk . blue ( `function` ) } (createElement) {
99
+ ${ colorArgs ( `var` ) } header = ${ colorArgs ( `this` ) } .$slots.header
100
+ ${ colorArgs ( `var` ) } body = ${ colorArgs ( `this` ) } .$slots.default
101
+ ${ colorArgs ( `var` ) } footer = ${ colorArgs ( `this` ) } .$slots.footer
102
+ return createElement(${ chalk . green ( `'div'` ) } , [
103
+ createElement(${ chalk . green ( `'header'` ) } , header),
104
+ createElement(${ chalk . green ( `'main'` ) } , body),
105
+ createElement(${ chalk . green ( `'footer'` ) } , footer)
106
+ ])
107
+ }
108
+ })
109
+ `
110
+ }
111
+ const VM_$SCOPED_SLOTS = {
112
+ category : cat ,
113
+ name : `vm.$scopedSlots` ,
114
+ type : `{ [name: string]: props => VNode | Array<VNode> }` ,
115
+ read : `Read only` ,
116
+ details : `Used to programmatically access ${ chalk . green ( `scoped slots` ) } .
117
+ For each slot, including the ${ colorArgs ( `default` ) } one, the object
118
+ contains a corresponding function that returns VNodes.
119
+ Accessing ${ colorArgs ( `vm.$scopedSlots` ) } is most useful when writing
120
+ a component with a ${ chalk . green ( `render function` ) } .`
121
+ }
122
+ const VM_$REFS = {
123
+ category : cat ,
124
+ name : `vm.$refs` ,
125
+ type : `Object` ,
126
+ read : `Read only` ,
127
+ details : `An object that holds child components that have ${ colorArgs ( 'ref' ) } registered.`
128
+ }
129
+ const VM_$IS_SERVER = {
130
+ category : cat ,
131
+ name : `vm.$isServer` ,
132
+ type : `boolean` ,
133
+ read : `Read only` ,
134
+ details : `Whether the current Vue instance is running on the server.`
135
+ }
136
+ const VM_$ATTRS = {
137
+ category : cat ,
138
+ name : `vm.$attrs` ,
139
+ type : `{ [key: string]: string }` ,
140
+ read : `Read only` ,
141
+ details : `Contains parent-scope attribute bindings that are not
142
+ recognized (and extracted) as props. When a component doesn’t
143
+ have any declared props, this essentially contains all
144
+ parent-scope bindings except for ${ colorArgs ( `class` ) } and ${ colorArgs ( `style` ) } ,
145
+ and can be passed down to an inner component via
146
+ ${ colorArgs ( `v-bind="$attrs"` ) } - useful when creating higher-order components.`
147
+ }
148
+ const VM_$LISTENERS = {
149
+ category : cat ,
150
+ name : `vm.$listeners` ,
151
+ type : `{ [key: string]: Function | Array<Function> }` ,
152
+ read : `Read only` ,
153
+ details : `Contains parent-scope ${ colorArgs ( `v-on` ) } event listeners
154
+ (without ${ colorArgs ( `.native` ) } modifiers). This can be passed down to
155
+ an inner component via ${ colorArgs ( `v-on="$listeners"` ) } - useful when
156
+ creating higher-order components.`
157
+ }
41
158
42
159
43
160
module . exports = {
0 commit comments