需求:超时自动退出登录
methods: {
testTime() {
this.currentTime = new Date().getTime(); //更新当前时间
if (this.currentTime - parseInt(localStorage.getItem('lastTime')) > this.timeOut) { //判断是否超时(超时自动退出登录)
this.cleanAllCache(); //清除所有缓存数据
//下面就可以按自己的方式跳转到登录页
window.location.href = `${process.env.VUE_APP_OAUTH_URL}${this.OAUTH}logout?redirect_uri=${window.location.origin}${this.FOLDER_SUFFIX}`;
}
},
setLastTime() {
localStorage.setItem('lastTime', new Date().getTime().toString());//更新操作时间
}
}
created() {
//保存上次进去的时间戳
this.setLastTime();
//用定时器监听是否长时间未操作
window.setInterval(this.testTime, 5 * 1000);
}
留下个赞???