I use vuex-persistedstate. But getters doesn't work. I checked state in Vue.js Devtools, state was present. But getters didn't have data. Like this.
So how can I use getters?
index.js in Vuex
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
login,
segments,
itemList,
orderList
},
plugins: [
createPersistedState()
]
})
index.js in vue-router (I want to use getters for login status check)
import store from '@/store'
Vue.use(Router)
const ifAuthenticated = (to, from, next) => {
if (store.getters.loginStatus) {
next()
} else {
next({
path: '/login',
query: { redirect: to.fullPath }
})
}
}
login.js (store module in Vuex)
const state = {
loginStatus: false,
email: '',
isStaff: false,
company: '',
token: ''
}
const getters = {
loginStatus: () => state.loginStatus,
email: () => state.email,
isStaff: () => state.isStaff,
company: () => state.company,
token: () => state.token
}