Here is my code, i am using vuex-persisted-state as a plugin and state persists after page reload , However when i console my state in the middleware it always returns false :
store code:
import Vuex from 'vuex'
const createStore = () => {
return new Vuex.Store({
state: () => ({
truthy: false,
}),
mutations: {
changeState(state, truthy) {
state.truthy = truthy
}
},
})
}
export default createStore
My page code
<template>
<button @click="change">Change</button>
</template>
<script>
export default {
middleware: 'authenticated',
methods: {
change() {
this.$store.commit('changeState', true)
}
}
}
</script>
My Plugin Code
import createPersistedState from 'vuex-persistedstate'
export default ({ store }) => {
createPersistedState({})(store)
}
Middleware Code
export default function ({ store, redirect,req }) {
console.log(store.state)
}