可以使用 secure-ls
来给前端加密。
import SecureLS from "secure-ls";
const ls = new SecureLS({
encodingType: "base64",
isCompression: false,
encryptionSecret: ""
});
export default {
set: (key, value) => {
ls.set(key, value);
},
get: (key) => {
return ls.get(key);
},
remove: (key) => {
ls.remove(key);
}
}
使用方式如下:
import Ls from '@/utils/ls'
Ls.set(USER_INFO, userInfo);
let userInfo = Ls.get("USER_INFO");