rcc-lasting
v1.0.3
Published
vuex持久化
Downloads
14
Readme
#rcc-lasting
vuex持久化 可以使用sessionStorage,localStorage来分别存储
##Installation
$ npm install rcc-lasting -S
##Usage
import lasting from 'rcc-lasting'
const store = new Vuex.Store({
// ...
plugins: [lasting()]
})
分别使用sessionStorage,localStorage来存储响应的数据
import lasting from 'rcc-lasting'
const store = new Vuex.Store({
state:{
a:'',
b:''
}
// ...
plugins: [lasting({
Ls:['a'], //state.a 存储到localStorage
Ss:['b'] //state.b 存储到sessionStorage
})]
})
Nuxt.js
// nuxt.config.js
...
plugins: [{ src: 'plugins/storeLasting.js', ssr: false }]
...
// plugins/storeLasting.js
import lasting from 'rcc-lasting'
export default ({ store }) => {
lasting(
{
key: 'vuex',
Ls:['a'], //state.a 存储到localStorage
Ss:['b'] //state.b 存储到sessionStorage
}
)(store)
}
##API
lasting([options])
- key <String> : 本地存储的key名称。(默认:vuexStorage)
- Ls <Array> : 需要存到localStorage的key。(默认:[ ])
- Ss <Array> : 需要存到sessionStorage的key。(默认:[ ])