//设置cookie
var exp = new Date();
exp.getMilliseconds()
exp.setTime(exp.getTime() + 60 * 1000);//过期时间 1分钟
console.log(exp.toGMTString())
//this.setCookie('isLogin', true, exp.toGMTString())
document.cookie = 'isLogin' + '=' + true + ';expires=' + exp.toGMTString();
//此处赋值的是世界时间,和我国的时间差8小时,不过千万不要把这8小时加上,直接赋值指定时长就好
//获取cookie,可以用js-cookie
import Cookies from 'js-cookie';
updated() {
if (!Cookies.get('isLogin')) {
this.¥store.dispatch(setSignOut)//清空用户登录信息
this.¥router.push({
name: 'login'//跳到登录页
});
}
},
activated() {
if (!Cookies.get('isLogin')) {
this.¥store.dispatch(setSignOut)
this.¥router.push({
name: 'login'
});
}
},
//因为没有统一的入口,所以我在首页的updated和activated中添加的判断,并没有在每个页面都加,感觉没必要
//还可以用这种方式获取cookie,不需要导包了
function getCookie(cname){
var name = cname + =;
var ca = document.cookie.split(';');
for(var i=0; i
var c = ca[i].trim();
if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
}
return ;
}