vue.js - 类型错误 : Converting circular structure to JSON Vuejs

标签 vue.js vuex

我遇到了错误 “TypeError:将循环结构转换为 JSON” 在使用 vuex-persistedstate 插件时。

import createPersistedState from 'vuex-persistedstate'

const store = new Vuex.Store({
  // ...
  plugins: [createPersistedState()]
})

我找到了一些使用插件的解决方案,没有错误,如下所示

plugins: [createPersistedState]

但它不保存状态详细信息。

最佳答案

您没有提到要将数据存储在何处。由于我将 vuex 数据存储在 localStorage 中,因此我的代码如下所示:

import createPersistedState from 'vuex-persistedstate'

const store = new Vuex.Store({
   // ...
   plugins: [createPersistedState(
     storage: window.localStorage
   )]
 })

基本上,只需将 storage: window.localStorage 传递给您的 createPersistedState() 方法即可。

尽情享受吧!

关于vue.js - 类型错误 : Converting circular structure to JSON Vuejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55529722/

相关文章:

vue.js - 重新加载时Vue路由器重定向到主页

vue.js - VueJS - 未知的本地操作类型 : addProductToCart, 全局类型:cart/addProductToCart

javascript - 在vue组件上编辑数据时如何显示输入类型日期的值?

html - 如何使用动画迭代 vue 组件

javascript - 从组件访问 Vuex Store 中的 Mutator 会产生未知突变类型错误

javascript - Vue.js - 带有查询参数的搜索表单

javascript - v-for ="n in 10"中的起始范围从零开始

javascript - Gsap 无法与 typescript 正常工作

javascript - 使用 VueX 在 getter 中接受参数并进行过滤

vuejs2 - 在突变 (Vuex) 后更改路由 (VueRouter) 的最佳实践