小程序控制台报错:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'a'
| property '$options' -> object with constructor 'Object'
| property 'propsData' -> object with constructor 'Object'
| ...
| property 'observer' -> object with constructor 'Object'
--- property '_component' closes the circle
at Object.stringify (<anonymous>)
at Wt (WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1
at Object.hIe [as setStorageSync] (WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at e.<computed> (WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at Object.LIe.<computed> (WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at I (WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at Object.p (WAServiceMainContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at Object.p (WASubContext.js?t=wechat&s=1743132656966&v=3.7.1:1)
at Proxy.value (index.js:1)(env: Windows,mp,1.06.2407120; lib: 3.7.1)
图片:
报错原因,解决思路:这个报错可能是页面使用setStorageSync当中的json一直在循环报错导致的,可以看下你的数据是不是一直在循环嵌套,所以调用setStorageSync这个方法的时候,一直在循环所以报了
我这边是因为页面在做长列表性能优化的时候使用了uni.createIntersectionObserver()生成实例的页面,如果同时使用了存取缓存,getStorageSync,setStorageSync,会有这个报错,原因是因为在生成observer实例的时候,在控制台可以看到数据里面无限循环,在使用存储的时候,存储的方法调用的Json会无限循环,导致如图报错,解决方法是,在存储之前,去掉observer实例再存储
我这的解决方法是:
原来:
解决之后