uni-app 延时执行某个方法的解决方案

定义一个 timer

data() {
    return {
        timer: '',
    }
},

定时器   

this.sendMsg_GetAddressList 为要延时调用的方法   1000 为1秒后执行
methods: {
     startTimer(){
          this.timer = setTimeout(this.sendMsg_GetAddressList, 1000);
     },
   sendMsg_GetAddressList(){
         alert("延时1秒后执行的");
   }, 
}, 
beforeDestroy() {
  clearTimeout(
this.timer);
}

posted @ 2023-01-13 15:56  海乐学习  阅读(2674)  评论(0编辑  收藏  举报