vuejs-storage
vuejs-storage copied to clipboard
Uncaught TypeError: Cannot set property 'String' of undefined
2.4.0 has this bug. 2.3.3 is ok.
my store/index.ts
file
import Vue from "vue"
import Vuex from "vuex"
import vuejsStorage from "vuejs-storage"
const getters: any = require("./getters")
import login from "./modules/login"
Vue.use(Vuex)
const store = new Vuex.Store({
getters,
modules: {
login
},
plugins: [
vuejsStorage({
keys: ["login"],
namespace: "planx"
})
]
})
export default store
Can you show me ./modules/login
?
./modules/login
import * as actions from "./actions"
const state = {
token: null,
user: {},
userinfo: {}
}
const mutations = {
setToken(state, token) {
state.token = token
},
setUser(state, user) {
state.user = user
},
setUserInfo(state, userinfo) {
state.userinfo = userinfo
},
clearData(state) {
state.token = null
state.user = {}
state.userinfo = {}
}
}
export default {
state,
actions,
mutations
}
actions is empty
Is token
a object? Or string?
If it is an object, it might happened when the plugin try to merge state.
See: https://github.com/maple3142/vuejs-storage/issues/9#issuecomment-389123728
token is string.
I set token = "" replace null, It works.
I cannot reproduce the bug. https://jsfiddle.net/vc7qt2ov/
Did you add anything to an object with key String
elsewhere?
I use vuejs-storage with vuex plugin vuex-orm.
I create a repo try to reproduce the bug, but failed. https://github.com/transtone/vuejs-storage-debug
I don't have time to test this, get back to 2.3.3.
Does it works without vuex-orm
?
The main changes between 2.4.0 and 2.3.3 is builtin merge function can handle deep merge.
I ran into a similar problem today. In my store's state, I had user: null
. This gets set to an Object after the user logs in. Everything worked fine initially. When I tried to refresh the page after logging in, however, I was told that e is null
(this is after it's gone through Webpack). Everything started working once I changed user: null
to user: {}
in my store's state.