在App.vue添加代码
<template>
<div id="app" @mousemove="moveEvent" @click="moveEvent">
<router-view />
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
timmer: null
}
},
methods: {
moveEvent: function() {
let path = ['/login']
if(!path.includes(this.$route.path)) {
clearTimeout(this.timmer)
this.init()
}
},
init: function() {
this.timmer = setTimeout(() => {
sessionStorage.clear()
this.$router.push({
path: '/login'
})
}, 1000*60*30)
}
}
}
</script>
延时的时间单位是毫秒 1000*60*30就是30分钟,可以根据要求的时间进行修改