Why component data is a function?

Why must the components in the data is a function, and then return an object, and the new Vue instances where, data can be a direct target?

// data
data() {
return {
message: "sub-components"
childName:this.name
}
}

// New View
new view ({
on: '#app'
router,
template: '<App/>',
components: {App}
})

  Because the components are used to duplicate, and the JS object is a reference relationship, if the data is a component object that it is not so isolation scope, attribute data values subassembly affect each other,

If the component is a function of the data option, each instance can maintain a separate copy of the object is returned, the attribute data values ​​between the components do not affect each instance;

 The example of the new Vue is not going to be reused, so the question of the referenced object does not exist.

Guess you like

Origin www.cnblogs.com/lovekunkun/p/12144596.html