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"
},

 

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