vuex持久化 vuex-persistedstate
1.下载
npm install --save vuex-persistedstate
2.在vuex里面引入,默认是localStorage
import persistedState from ‘vuex-persistedstate‘ export default new Vuex.Store({ // ... plugins: [persistedState()] })
3.使用sessionStorage
plugins: [ persistedState({ storage: window.sessionStorage }) ]
4.使用cookie
的情况
import persistedState from ‘vuex-persistedstate‘ import * as Cookies from ‘js-cookie‘ export default new Vuex.Store({ // ... plugins: [ persistedState({ storage: { getItem: key => Cookies.get(key), setItem: (key, value) => Cookies.set(key, value, { expires: 7 }), removeItem: key => Cookies.remove(key) } }) ] })
相关推荐
CSCCockroach 2020-09-15
lbPro0 2020-07-05
MrSunOcean 2020-06-21
lylwanan 2020-06-14
ShaLiWa 2020-05-25
墨龙吟 2020-04-24
MrSunOcean 2020-04-24
H女王范儿 2020-04-22
lbPro0 2020-04-16
ShaLiWa 2020-02-29
ShaLiWa 2020-01-17
MrSunOcean 2020-01-03
lbPro0 2020-01-01
H女王范儿 2019-12-29
MrSunOcean 2019-12-27