类似于某银行app,时间长不操作页面,执行相应业务
<template>
<!--触发事件-->
<div id="app" @touchend="moveEvent" @click="moveEvent">
12321
</div>
</template>
<script>
export default {
name: "App",
data() {
return {
// 用户超时定时器
timmer: null
};
},
methods: {
/**
监听鼠标滑动和点击事件,重置页面用户未操作超时时间
*/
moveEvent() {
let path = ["/login"];
if (!path.includes(this.$route.path)) {
clearTimeout(this.timmer);
this.init();
}
},
/**
用户超时定时器 5秒钟
*/
init() {
this.timmer = setTimeout(() => {
// 执行事件
this.$router.push({
path: "/login"
});
}, 5000);
}
}
};
</script>
<style lang="less" scoped>
#app {
height: 1000px;
background: red;
}
</style>