导入:加密
// 安装
npm install --save js-base64
// 引入
const Base64 = require('js-base64').Base64
创建函数:
created()
{
this.getCookie()
},
methods:{
//储存
setCookie(name ,pws ,exdays)
{
var exdate = new Date(); //获取时间
exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays);
window.document.cookie = "userName" + "=" + name + ";path=/;expires=" + exdate.toGMTString();
let passWord = Base64.encode(pws)
window.document.cookie = "userPwd" + "=" + passWord + ";path=/;expires=" + exdate.toGMTString();
},
//获取
getCookie()
{
if (document.cookie.length > 0) {
var arr = document.cookie.split('; ');
for (var i = 0; i < arr.length; i++) {
var arr2 = arr[i].split('=');
if (arr2[0] == 'userName') {
this.loginForm.username = arr2[1];
} else if (arr2[0] == 'userPwd') {
this.loginForm.password=Base64.decode(arr2[1]);
this.checked = true
}
}
}
},
//删除
clearCookie()
{
this.setCookie("", "", -1);
}
}