最近有个需求,就是检测页面无操作10分钟后返回登录页,提供一种思路,不需要后台配合,也不用什么token,storage,给app.vue的div标签加上两个事件。滑动和点击事件,当滑动点击时开定时器跳转首页,setTimeout,定时间,当滑动或者点击的时候清除定时器,贴代码,暂时没发现bug,简单易懂
template代码
methods: { moveEvent: function () { clearTimeout(this.timmer); this.init(); }, init: function () { let path = ["/"]; this.timmer = setTimeout(() => { sessionStorage.clear(); if (!path.includes(this.route.path)) { this.router.push({ path: "/", }); } }, 10 * 60 * 1000); }, },