如何解决VUE中报错 [Vue warn]: Property or method “xxx” is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property
Vue.component(
'component1', {
props: {
},
template: ``,
data:{
a:"章三",
b:"李四",
},
mounted() {
},
methods: {}
}
)
Vue.component(
'component2', {
props: {
},
template: ``,
data() {
return {
a:"章三",
b:"李四",
}
},
mounted() {},
methods: {}
}
)
在使用vue组件中,组件要是个函数,即将data作为一个函数名、数据对象作为函数返回值来使用。因为组件可能被用来创建多个实例。如果data仍然是一个纯粹的对象,则所有的实例将共享引用同一个数据对象!通过提供data函数,每次创建一个新实例后,我们能够调用data函数,从而返回初始数据的一个全新副本数据对象