我已经基于github https://github.com/robinvdvleuten/vuex-persistedstate
设置了createdPersistedStateplugins / localStorage.js
import createPersistedState from 'vuex-persistedstate'
export default ({store}) => {
createPersistedState({
key: 'vuex',
paths: ['local']
})(store)
}
nuxt.config.js
plugins:[
{ src: '~/plugins/localStorage.js', ssr: false }
],
middleware / auth.js
import axios from 'axios'
export default function ({ store, params }) {
return axios.post( process.env.baseApi + '/login', {
email: 'example2@juanmerkado.com',
password: '12345678'
})
.then(response => {
//How to save it in createPersistedState or How can I do it here?
store.dispatch('token', response.data.token)
})
}
如何使用Middleware / auth.js中的createdPersistedSate将其保存在localStorage中?
答案 0 :(得分:1)
import createPersistedState from 'vuex-persistedstate'
export default ({store}) => {
createPersistedState({
})(store)
}
只需删除这一个key: 'vuex',
paths: ['local']