Property or method “id” is not defined on the instance but referenced during render. Make sure that

原文链接:http://www.sxzuqiu.cn/article/dca5c1c1422da91e4cd2f6df.html

报错详情

[Vue warn]: Property or method “id” 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. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties. 

报错原因

由于Vue不允许动态添加根级反应属性,因此必须通过预先声明所有根级反应数据属性来初始化Vue实例,即使是空值:

如果未在数据选项中声明,Vue将警告您渲染功能正在尝试访问不存在的属性。

这种限制背后有技术原因 - 它消除了依赖性跟踪系统中的一类边缘情况,并且还使Vue实例在类型检查系统中发挥更好的作用。但是在代码可维护性方面也有一个重要的考虑因素:data对象就像组件状态的模式一样。预先声明所有反应属性使得组件代码在以后重新访问或由其他开发人员阅读时更容易理解。

解决办法

再data中声名变量

data:{
   id:"id"
},

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章