目录Vue定时刷新数据,每隔5分钟执行一次vue局部定时刷新设置定时器局部刷新清除定时器总结vue定时刷新数据,每隔5分钟执行一次 data() { return { t
data() {
return {
timer: null
}
},
mounted() {
// 每隔5分钟定时刷新
this.timer = setInterval(() => {
this.getFxItemlist();
}, 300000)
},
beforeDestroy() {
clearInterval(this.timer);
},
methods: {
getFxItemlist() {
...
}
}
定时刷新一般都会想到定时器,vue局部定时刷新如下:
timer: "",//定时器
//定时器刷新待办事项
this.timer = setInterval(() => {
self.reload();
}, 1000);
<div class="DealtTop" v-if="isRefreshAlive">
isRefreshAlive: true, //刷新
//局部刷新
reload() {
this.isRefreshAlive = false;
this.$nextTick(function() {
this.isRefreshAlive = true;
});
},
如果是在父子组件中,还需要加上provide / inject配合使用,如下:
provide() {
return {
reload: this.reload
};
},
destroyed(){
clearInterval(this.timer);
},
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: vue实现定时刷新数据,每隔5分钟执行一次
本文链接: https://www.lsjlt.com/news/177841.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0