vue监听页面,无操作一分钟刷新页面。监听页面所有点击事件跟触摸事件,无操作1分钟重新调用后端接口刷新页面数据
vue监听页面,无操作一分钟刷新页面,监听页面所有点击事件跟触摸事件,无操作1分钟重新调用后端接口刷新页面数据。
·
vue监听页面,无操作一分钟刷新页面,监听页面所有点击事件跟触摸事件,无操作1分钟重新调用后端接口刷新页面数据
let optAction=false //定义判断条件false,if(!optAction)来判断
let autoTime //定时器
const that=this
// console.log("初始化调接口")
const touchEvent=function() {
// console.log("操作中")
optAction=true //让判断条件为true
clearTimeout(autoTime) //清除自动刷新页面定时器
autoTime=setTimeout(function() {
optAction=false //页面无操作后3秒,重时开启定时器
// console.log("无操作")
},3000)
}
this.$nextTick(() => {
//鼠标事件
this.$refs.homeId.addEventListener('mousemove',touchEvent);//鼠标移动
this.$refs.homeId.addEventListener('mousedown',touchEvent);//鼠标按下
// this.$refs.homeId.addEventListener('mouseup',touchEvent);//鼠标释放
// this.$refs.homeId.addEventListener('click',touchEvent);//点击事件
//触摸事件
this.$refs.homeId.addEventListener('touchstart',touchEvent); //手指放到屏幕上时触发
this.$refs.homeId.addEventListener('touchmove',touchEvent);//手指在屏幕上滑动式触发
// this.$refs.homeId.addEventListener('touchend',handleEndEvent); //手指离开屏幕时触发
//this.$refs.homeId.addEventListener('touchcancel',handleEndEvent);//系统取消touch事件的时候触发,这个好像比较少用
//键盘事件
// this.$refs.homeId.addEventListener('keyup',touchEvent);//键盘抬起事件
this.$refs.homeId.addEventListener('keydown',touchEvent);//键盘按下事件
})
//每1分钟刷新一次页面数据
setTimeout(function() {
setInterval(function() {
if(!optAction) {
// console.log("刷新页面");
// window.location.reload(); 该行直接刷新浏览器
that.getPageData();//重新调取接口
}
},1000*60)
},5000)
如果觉得可以就点个👍吧,欢迎粉丝收藏,土豪打赏,你的鼓励将是我创作的最大动力!
qq群933053581
更多推荐
所有评论(0)