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)

出现了错误。

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





  • 2020-12-21 09:00:20

    Window.matchMedia() 方法详解

    matchMedia() 返回一个新的 MediaQueryList 对象,表示指定的媒体查询字符串解析后的结果。 matchMedia() 方法的值可以是任何一个 CSS @media 规则 的特性, 如 min-height, min-width, orientation 等。 MediaQueryList 对象有以下两个属性:

  • 2020-12-21 09:42:42

    iframe.contentWindow 操作iframe

    注:iframe.contentWindow这里,返回的是iframe的window对象,所以后面可以接着调用document方法,再接着调用getElementByTagName。那么就可以对iframe里面的元素进行操作了。

  • 2020-12-21 14:00:19

    iframe + postMessage跨域通信

    在实际项目开发中可能会碰到在 a.com 页面中嵌套 b.com 页面,这时第一反应是使用 iframe,但是产品又提出在 a.com 中操作,b.com 中进行显示,或者相反。

  • 2020-12-22 12:02:41

    ios开发优秀的开源框架,demo集合

    期待大家和我们一起共同维护,同时也期望大家随时能提出宝贵的意见(直接提交issues即可)。请广大网友只按照目录结构(即使目录结构有问题)添加三方库,并提交pull request。目录问题大家提出issues后楼主会及时更改的。