wepy 小程序定時器(驗證碼倒計時) 數據綁定頁面無刷新


 每次改變數據的時候記得調用  this.$apply() 

驗證碼倒計時


使用的vant-weapp  UI組件

wxml:

1    <van-col span="10" style='text-align:center'>
3             <view wx:if="{{sendAuthCode}}"bindtap="getCode()">獲取驗證碼</view>
6             <view wx:elif="{{!sendAuthCode}}">{{auth_time}}S</view>
8     </van-col>

JS:

 1 data = {
 2     auth_time: 5,//倒計時
 3     sendAuthCode: true,//控制獲取驗證碼
 4   };
 5 methods = {
 6     getCode () {//獲取驗證碼
 7       let that = this
 8       this.sendAuthCode = false
 9       var auth_timetimer = setInterval(() => {
10         this.auth_time--;
11         that.$apply()
12         console.log(this.auth_time)
13         if (this.auth_time <= 0) {
14           this.sendAuthCode = true;
15           that.$apply()
16           clearInterval(auth_timetimer);
17         }
18       }, 1000)
19     }
20 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM