You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
restrictions: `Only accepts ${colorArgs('Function')} when used in a component definition.`,
15
+
details: `The data object for the Vue instance. Vue will recursively convert its properties into getter/setters
16
+
to make it “reactive”. ${chalk.bold('The object must be plain')}: native objects such as browser API objects
17
+
and prototype properties are ignored. A rule of thumb is that data should just be data -
18
+
it is not recommended to observe objects with its own stateful behavior.Once observed, you
19
+
can no longer add reactive properties to the root data object. It is therefore recommended
20
+
to declare all root-level reactive properties upfront, before creating the instance. After the
21
+
instance is created, the original data object can be accessed as ${colorArgs('vm.$data')}. The Vue instance
22
+
also proxies all the properties found on the data object, so ${colorArgs('vm.a')} will be equivalent to
23
+
${colorArgs('vm.$data.a')}. Properties that start with ${colorArgs('_')} or ${colorArgs('$')} will ${chalk.bold('not')} be proxied on the Vue instance because they may conflict
24
+
with Vue’s internal properties and API methods. You will have to access them as ${colorArgs('vm.$data._property')}.
25
+
When defining a ${chalk.bold('component')}, ${colorArgs('data')} must be declared as a function that returns the initial data object,
26
+
because there will be many instances created using the same definition.
27
+
If we still use a plain object for ${colorArgs('data')}, that same object will be ${chalk.bold('shared by reference')}
28
+
across all instances created! By providing a ${colorArgs('data')} function, every time a new instance is created, we can simply call it to return a
29
+
fresh copy of the initial data. If required, a deep clone of the original object can be obtained by passing
30
+
${colorArgs('vm.$data')} through ${colorArgs('JSON.parse(JSON.stringify(...))')}.`,
31
+
example: `
32
+
${colorArgs('var')} data = { a: ${colorPrimitive('1')} }
33
+
${colorComment('// direct instance creation')}
34
+
${colorArgs('var')} vm = ${colorArgs('new')} Vue({
35
+
data: data
36
+
})
37
+
vm.a ${colorComment('// -> 1')}
38
+
vm.$data === data ${colorComment('// -> true')}
39
+
${colorComment('// must use function when in Vue.extend()')}
0 commit comments