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)

出现了错误。

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





  • 2018-10-28 10:50:26

    VectorDrawable简单介绍

    在项目中使用矢量图至少可以缩小我们apk包的尺寸,而且可以在屏幕适配时提供很大的方便,因为矢量图是分辨率无关的。

  • 2018-10-28 11:14:29

    矢量资源工具Vector_Asset_Studio

    Android Studio有一个称为“Vector Asset Studio”的工具, 它可以将SVG文件和PSD文件转化为工程可用的矢量可绘制资源(vector drawable resources),

  • 2018-10-28 11:16:09

    Android vector标签 PathData 画图超详解

    SVG是一种矢量图格式,是Scalable Vector Graphics三个单词的首字母缩写。在xml文件中的标签是<vector>,画出的图形可以像一般的图片资源使用,例子如下

  • 2018-10-30 00:16:41

    android ToolBar 设置颜色

    app:popupTheme——有时候我们有需求:ActionBar文字是白的,ActionBar Overflow弹出的是白底黑字让ActionBar文字是白的,那么对应的theme肯定是Dark。可是让ActionBar弹出的是白底黑字,那么需要Light主题。这时候popupTheme就派上用场了。android:theme 与app:theme——在AppCompat v21里,提供了一个快速方便的方法设置Toolbar的主题,使用app:theme。而新版本22.1.x中,AppCompat 允许对 Toolbar 使用 android:theme代替 app:theme。最好的一点是:它会自动继承父视图的theme ,并且兼容所有APIv11以上的设备。

  • 2018-11-01 22:08:19

    Android Toolbar左、中、右对齐

    默认的Android Toolbar中添加子元素view是从左到右依次添加。需要注意的是,Android Toolbar为自身的NavigationIcon(app:navigationIcon)最靠右,Logo(app:logo)紧接NavigationIcon、Title(app:title)接续Logo、保留了默认的位置(从左边到右)。这些Android Toolbar保留的系统设置字段将挤压开发者自己安放在Toolbar中的子view,如图所示: