这种报错一般是数据处理的问题。比如:
我想在代码中把某个数组对象转换为Json字符串
JSON.stringify(this.$store.state.tagsView.visitedViews)
该数组对象的数据结构为:

这样转换就会造成“TypeError: Converting circular structure to JSON”报错。
但其实在需求中我只用到path字段的信息,所以应该处理完再转化为json字符串:
const visitedViews_temp = this.$store.state.tagsView.visitedViews
const arr_temp = []
for (let i = 0; i < visitedViews_temp.length; i++) {
arr_temp.push(visitedViews_temp[i].path)
}
if (arr_temp && arr_temp.length > 0) {
const temp = JSON.stringify(arr_temp)
sessionStorage.setItem('visitedViews', temp)
}
这样 sessionStorage.setItem('visitedViews', temp) 就不会报错了
而且根据尽可能减少资源开销的原则,也应该要这么做。
3459

被折叠的 条评论
为什么被折叠?



