问题

在项目中控制台报下图错误:

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.
在这里插入图片描述

解决

  1. 查看报错详情,在全局文件查找 toJSON 字段,并没有找到项目中有该字段,于是怀疑是vue实例内部问题。
  2. 发现每个报错中都是在single组件中报错的,定位到single组件。
  3. 发现组件内向子组件传入了single整个vue实例,如下图所示:
    在这里插入图片描述
  4. 为了实现相同的功能,便在data重新声明一个属性,并且将实例赋值进去。
    在这里插入图片描述
  5. 修改后代码:
    在这里插入图片描述
  6. 测试后,控制台无报错。

(具体原因有待研究)

参考

Vue错误——Property or method “toJSON” is not defined on the instance but referenced during render.

Logo

前往低代码交流专区

更多推荐