Property or method "toJSON" is not defined on the instance but referenced during render.

2020-05-27 11:35:50

其实这并不是一个错误,这是一个提醒,网上又很多也遇到这样问题的,但并不是和我的一样。

有人遇到这样的问题: 参考地址  Property or method "toJSON" is not defined on the instance but referenced during render. Make sure t

    

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”不是在实例上定义的,而是在呈现过程中引用的。确保此属性为通过初始化属性,确保此属性在数据选项中或对于基于类的组件是活动的


最后发现我用了termid这个字段。定义的时候termid:'  ',但是赋值的时候termid=data.id ;但是这个dataid是个数字。最后接口需要字符类型的我又通过termid.toString()转为了字符。


所以初始化定义的数据类型和赋值的数据类型格式不一样时,就会出现这种错误了。


还有种错误我本来定义的是数组。但是最后传给后台的时候必须传字符串。我就把这个数组toSting了。这违背了我开始定义的数组。而赋值成了字符串。这个时候也会报这种错误。


也有人遇到这样的问题 参考地址 Vue错误——Property or method "toJSON" is not defined on the instance but referenced during render.


我的vue在注册过程中报了这个错误:


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.




而且影响了router的传值。


很奇怪的是引起这个问题的原因在于,在于在生命周期的created方法中报错:


  created() {

    console.log('created');

    console.log(this);

    // console.log('params:' + JSON.stringify(this.$route.params));

  },


一旦去掉console.log(this)就能解决这个问题


为什么会出现这个问题?后续研究研究


通过第二种,我发现了我的问题。我是先 

oElm = document.getElementById(id)

然后

console.info('eELM',oElm)

出现了错误。

这样大家应该心里明白了吧。





  • 2021-01-08 16:47:37

    nodejs如何使用fetch

    node 中没有实现 fetch,你可以使用 node-fetch,使得在 node 中也可以使用 fetch.

  • 2021-01-08 16:49:59

    CommonJs 与 ESModule区别

    node中模块导入require是一个内置的函数,因此只有在运行后我们才可以得知模块导出内容,无法做静态分析

  • 2021-01-08 16:54:08

    如何在 Node.js 中使用 import / export 的三种方法

    注:第1、2种方法均是借助 babel,需要注意的是文章使用的babel版本 < 7。从 babel 7.X 版本开始,部分包名、用法发生了些许变化,大体与7之前的用法类似,详细请到官方手册学习 7.X 版本的改动(Babel 踩坑总结(三) —— 7.X 版本升级是我对 7.X 版本三大改动的总结)