解决报错TypeError: Converting circular structure to JSON --> starting at object with constructor

报错内容:vue.esm.js:5105 [Vue warn]: Error in nextTick: "TypeError: Converting circular structure to JSON--&

报错内容:

vue.esm.js:5105 [Vue warn]: Error in nextTick: "TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'VueComponent'
    |     property '_scope' -> object with constructor 'EffectScope'
    |     property 'effects' -> object with constructor 'Array'
    |     index 0 -> object with constructor 'Watcher'
    --- property 'vm' closes the circle" 

这个错误其实是因为被JSON转化的对象里的子项存在循环引用,JSON转化时其实也是一个深度拷贝的过程,但是存在循环引用的对象,JSON拷贝转化时会失败,解决方案不止一种,这里讲下我使用的方案circular-json。

// 安装插件包:
npm install -S circular-json    

// 在项目中引用:
import CircularJSON from 'circular-json'

// JSON格式转化:
CircularJSON.stringify(存在循环引用的数组、对象)

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755047676a5232954.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信