在App.vue中添加如下代码:
// 添加30min不操作就会清除用户信息事件
window.addEventListener('mousedown', (e) => {
this.setTimer();
}, false);
window.addEventListener('keyup', (e) => {
this.setTimer();
}, false);
window.addEventListener('scroll', (e) => {
this.setTimer();
}, false)
setTimer()方法如下:
setTimer () {
if (this.timer) clearTimeout(this.timer);
// 先判断有没有用户信息,用户为登录状态再添加提示
if (localDataUser.get()) {
this.timer = setTimeout(() => {
this.removeLocalStorage();
location.reload();
this.$message.warning('您已经超过30分钟未进行任何操作,请重新登录')
}, 30 * 60 * 1000)
}
},