data() {
timer: null,
screenLoading: false,
}
调用:
this.requestLoop()
轮询:
async requestLoop() {
try {
this.screenLoading = true;
const delayTime = 2 * 1000;
let res = await getMain(this.id);
if (res.code === 200) {
if (res.data.udid) {
this.screenLoading = false;
this.setStreamUrl(res.data.udid);
clearTimeout(this.timer);
return;
}
}
// 清除定时器
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.requestLoop();
}, delayTime);
} catch (error) {
console.error(error);
}
},
setStreamUrl() {}
获取数据:
getMain() {}
销毁:
beforeDestroy() {
clearTimeout(this.timer);
},