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回答

fishenal

2017-05-24

data需要通过工厂函数赋值,不能直接写对象


data: function () {

        return {x: 1}

}


or

es6写法

data() {

    return {x: 1}

}

0
1
狼灰灰
非常感谢!三克油,后面老师也讲到这块了。
2017-05-24
共1条回复

最容易上手的Vue2.0入门实战教程

快速入门Vue2.0,组件化开发一个数字产品电商平台

3966 学习 · 999 问题

查看课程