Reputation: 4268
const store = new Vuex.Store({
state: {
user: {
userName:'',
loggedInStatus: true,
authToken: ''
}
},
mutations: {
addWebToken: function(state, webToken){
state.user.authToken = webToken;
},
removeWebToken: function(state){
state.user.authToken = '';
}
},
methods:{
getToken:function (){
return store.state.user.authToken;
}
},
plugins: [createPersistedState()]
})
I have included "vuex-persistedstate.js" but it shows errors in console:
Uncaught TypeError: Cannot use 'in' operator to search for 'default' in undefined
at vuex-persistedstate.js:17
Uncaught ReferenceError: createPersistedState is not defined
When I ctrl + click on createPersistedState() call I can navigate to that file.
Upvotes: 1
Views: 1489
Reputation: 942
vuex-persistedstate.js need dependency on lodash and object-path. This error on vuex-persistedstate.js line 17, is the missing lodash dependency. If you already added lodash, make sure it's loaded inside the vuex-persistedstate module.
If you really want using plain js. You have to define window.merge = _.merge
and window.objectPath
have to be define with correct node module. You rather use webpack to use correctly this npm module.
More source : https://github.com/robinvdvleuten/vuex-persistedstate/issues/23
Upvotes: 1