Vue.component全局组件的data我加上了就报错,引用的是最新的VUE
来源:2-3 Vue的组件

狼灰灰
2017-05-23
Vue.component全局组件的data我加上了就报错,引用的是最新的VUE
Vue.component('uuTop', {
template: '<p>组件化{{uname}}</p>',
data:{
uname:"woxu10000"
}
});
报错:
[Vue warn]: The "data" option should be a function that returns a per-instance value in component definitions.
warn @ vue.js:440
strats.data @ vue.js:1103
mergeField @ vue.js:1331
mergeOptions @ vue.js:1326
Vue.extend @ vue.js:4168
Vue.(anonymous function) @ vue.js:4251
(anonymous) @ index.html?__hbt=1495549048954:21
vue.js:440 [Vue warn]: Property or method "uname" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
found in
---> <UuTop>
<Root>
1回答
-
data需要通过工厂函数赋值,不能直接写对象
data: function () {
return {x: 1}
}
or
es6写法
data() {
return {x: 1}
}
012017-05-24
相似问题