uniapp定时器的使用

//uniapp中的具体用法:我这里使用到了setInterval
data() {
return {
timer: null//定时器名称
};
},
//一般在页面需要的地方使用,这里我是放在了onshow()里
onShow() {
// console.log('onshow');
this.timer = setInterval(function() {
// 放入你自己的业务逻辑代码
}, 3000);
},
//uniapp中onHide()能监听到页面离开
onHide() {//离开页面前清除计时器
// console.log('onHide');
clearInterval(this.timer);
this.timer = null;
},

 

 

uniapp

popup的@change使用

在触发方法后 会调用很多遍

if(!e.show){
  //当e.show为false时也会调用很多遍  导致性能不好
}

解决办法 加入另一个判断条件拦截

bleChange(e) {
if(!e.show && this.bleLoading){  //bleLoading控制按钮的:loading 属性
this.bleLoading = false
this.ble_scan_close()
}
},

 

posted @ 2023-05-12 11:33  On1on  阅读(739)  评论(0)    收藏  举报