vue实现页面定时刷新
export default {
name: "TimerAndDataClear",
data () {
return {
timer: null
}
},
methods: {
setTimer() {
if(this.timer == null) {
this.timer = setInterval( () => {
//重置data
Object.assign(this.$data, this.$options.data())
this.methodGreate()
//1000表示定时1s刷新
}, 1000)
}
}
},
created: function() {
this.methodGreate()
// 每次进入界面时,先清除之前的所有定时器,然后启动新的定时器
clearInterval(this.timer)
this.timer = null
this.setTimer()
},
destroyed: function () {
// 每次离开当前界面时,清除定时器
clearInterval(this.timer)
this.timer = null
}
}
能力不足水平有限
有问题别说脏话
欢迎前来学习交流
email:1848199654@qq.com