vuex 加密保存在localstorage中,自定义名称

需求: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,这样就能够长期保存了,并且安全性足够

你可能感兴趣的:(web)