使用加密缓存及vuex数据持久化
import SecureLS from 'secure-ls'
export function useStorage(options = { encodingType: 'aes', encryptionSecret: 'yide-monitoring-system-manage' }) {
const ls = new SecureLS(options)
return {
getItem: (key: string) => ls.get(key),
setItem: (key: string, value: any) => ls.set(key, value),
removeItem: (key: string) => ls.remove(key),
removeAll: () => ls.removeAll()
}
}
- 使用以下方法数据默认将会通过
aes
加密压缩存储在 LocalStorage
useStorage 支持配置对象 具体看 https://softvar.github.io/secure-ls/#docs
- 该方法也是vuex 数据持久化的默认函数,可以指定需要加密持久化的模块
import { useStorage } from '@/utils/index'
const { setItem, getItem, removeItem,removeAll } = useStorage()
setItem('data', '123')
const data = getItem('data')
console.log(data)