共计 647 个字符,预计需要花费 2 分钟才能阅读完成。
报错内容:
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(存在循环引用的数组、对象)
原文地址: 解决报错 TypeError: Converting circular structure to JSON –> starting at object with constructor