vue 定时刷新单页面_vue 页面定时发送请求刷新数据

在页面中这样写

motheds:{

getListIng() {

// 这里是一个http的异步请求

if (this.$route.path == '当前路由' ) {

this.getData() //请求的函数

let _this = this;

console.log('定时请求-----------')

this.timeOut = setTimeout(() => {

_this.getListIng();

}, 5000);

} else {

this.timeOut = '';

}

},

}

created() {

if ( this.timeOut ) {

clearTimeout(this.timeOut);

}

this.getListIng();

},

computed: {

timeOut: {

set (val) {

this.$store.state.timeout.compileTimeout = val; //记得在全局中定义一下

},

get() {

return this.$store.state.timeout.compileTimeout;

}

},

}


版权声明:本文为weixin_28826961原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。