Uncaught TypeError: Converting circular structure to JSON

报错原因

执行JSON.stringify(obj)时 检测到obj 对象有递归引用 (对象的属性值引用了自身)

// 问题代码 -- 注意这里有互相引用的问题
this.param = this.contract[this.index]
this.param.list = this.contract

解决方法

赋值时使用 JSON.parse(JSON.stringify()) 来切断数据之间的相互引用

// 修改后的代码
this.param = JSON.parse(JSON.stringify(this.contract[this.index]))
this.param.list = JSON.parse(JSON.stringify(this.contract))

猜你喜欢

转载自www.cnblogs.com/codebook/p/12152682.html