boenfu / vuex-along

:memo: auto save and restore state for vuex
https://boenfu.github.io/vuex-along/
MIT License
259 stars 36 forks source link

我在vuex 中保存一个route对象会出现这个错误: TypeError: Cannot convert a Symbol value to a string #43

Closed sujiewen closed 3 years ago

sujiewen commented 3 years ago

如果不使用vuexAlong 就没有问题的

代码是这样的:

this.$store.dispatch('tagsView/addView', this.$route)

store 下面代码是这样的 const actions = { addView({ dispatch }, view) { dispatch('addVisitedView', view) dispatch('addCachedView', view) }, addVisitedView({ commit }, view) { commit('ADD_VISITED_VIEW', view) }, addCachedView({ commit }, view) { commit('ADD_CACHED_VIEW', view) } }

commit('ADD_VISITED_VIEW', view)执行这个代码就会引起这个问题

截屏2020-12-24 下午5 24 47
sujiewen commented 3 years ago

state.visitedViews.push( Object.assign({}, this.$route, { title: view.meta.title || 'no-name' }) ) 这里深拷贝有问题,改怎么解决?

boenfu commented 3 years ago

这看上去是 $route 里有用 Symbol 做 key 的, 但我们存储的介质是 localstorage, 无法存储 Symbol

sujiewen commented 3 years ago

应该是$route里面有对象嵌套引起的

GPX-NSlog commented 2 years ago

应该是$route里面有对象嵌套引起的 @sujiewen 怎么解决的

874910712 commented 1 month ago

应该是$route里面有对象嵌套引起的 @sujiewen 怎么解决的

我换了vuex-persistedstate插件就能解决了,是这个插件复制逻辑引起的,每次都是全部深度克隆整个state,state对象的属性中存储的某个对象有Symbol 做 key 的话,就会报错