使用了Vue 2.7,之前我是用 getCurrentInstance 然后直接获取的store 下面的 userId,后面加了一个 computed 。我以为computed 是和之前一样的就没改接口请求,然后就报错,其实 computed 返回的参数和 ref 是一样的需要 .value。
心得总结:
当出现 Converting circular structure to JSON
–> starting at object with constructor ‘Watcher’
| property ‘vm’ -> object with constructor ‘VueComponent’
| property ‘_scope’ -> object with constructor ‘EffectScope’
| property ‘effects’ -> object with constructor ‘Array’
— index 0 closes the circle
有 vm 、_scope、effects、Watcher 发生错误可能就是 Vue2.7 和 Vue3 ref 之类的需要 .value才能拿到真实的值。
总结
当请求接口出生出错:
1: 先查看参数是否正确。
2: 查看 axios 的 request 的值。
3: 如果 network 没有请求接口 大部分应该在 请求参数的时候就错误了。
在升级到Vue2.7后,作者发现使用computed获取store的userId时,遇到错误。问题在于computed返回的对象需通过.value获取实际值,类似Vue3的ref。错误信息提示涉及Vue的内部结构,如Watcher、VueComponent和EffectScope。解决方法是确保使用.value来访问ref或computed的值。当接口请求失败时,应首先检查参数和axios请求配置,因为错误可能在发送请求前就已经发生。
3301

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



