『解疑』对vue模板赋值整个vue实例时报错:Property or method toJSON is not defined
[vue报错]Property or method "toJSON" is not defined on the instance but referenced during render....解决对vue模板赋值整个vue实例时报错: Property or method "toJSON" is not defined
·
问题
在项目中控制台报下图错误:
Property or method “toJSON” 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.
解决
- 查看报错详情,在全局文件查找 toJSON 字段,并没有找到项目中有该字段,于是怀疑是vue实例内部问题。
- 发现每个报错中都是在single组件中报错的,定位到single组件。
- 发现组件内向子组件传入了single整个vue实例,如下图所示:
- 为了实现相同的功能,便在data重新声明一个属性,并且将实例赋值进去。
- 修改后代码:
- 测试后,控制台无报错。
(具体原因有待研究)
参考
Vue错误——Property or method “toJSON” is not defined on the instance but referenced during render.
更多推荐
已为社区贡献3条内容
所有评论(0)