vuex 加密保存在localstorage中,自定义名称
需求:vuex中的信息存在localStorage中,但是安全性不够1,安装secure-lsnpm i secure-ls2,使用在store.js中写入一下代码import SecureLS from "secure-ls";var ls = new SecureLS({encodingType: "aes",isCompression: false,encr...
·
需求:vuex中的信息存在localStorage中,但是安全性不够
1,安装secure-ls
npm i secure-ls
2,使用
在store.js中写入一下代码
import SecureLS from "secure-ls";
var ls = new SecureLS({
encodingType: "aes",
isCompression: false,
encryptionSecret: "你的key"
});
import config from "@/config";
Vue.use(Vuex);
export default new Vuex.Store({
plugins: [
createPersistedState({
key: "存在localstorage里面的名称",
storage: {
getItem: key => ls.get(key),
setItem: (key, value) => ls.set(key, value),
removeItem: key => ls.remove(key)
}
})
],
state:{},
mutations:{},
actions:{}
3,这样就能够长期保存了,并且安全性足够
更多推荐

所有评论(0)