Home >WeChat Applet >Mini Program Development >WeChat Mini Program Example: How to count down the verification code (code)

WeChat Mini Program Example: How to count down the verification code (code)

不言
不言Original
2018-08-16 17:54:103367browse

The content of this article is about the WeChat applet example: how to verify the countdown of the code (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

// pages/login/login.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    countdown: 60,
    isShow:true
  },
  //倒计时
  count:function(that){
    var interval = setInterval(function () {
      var countdown = that.data.countdown;
      if (countdown == 0) {
        that.setData({
          isShow: true,
          countdown: 60
        })
        clearInterval(interval)
      } else {
        countdown--;
        that.setData({
          isShow: false,
          countdown: countdown
        })
      }
    }, 1000)
  },
  //设置手机号
  shj: function (e) {
    this.setData({
      tel: e.detail.value
    })
  },
  //获取验证码
  send: function () {
    var that=this;
    wx.showToast({
      title: '验证码发送成功',
      icon: 'none',
      duration: 1000,
      success: function () {
        that.count(that)
      }
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

})

Related recommendations:

WeChat Mini Program Example: How to obtain and render data (with code)

WeChat Mini Program Example: Code implementation for form submission

The above is the detailed content of WeChat Mini Program Example: How to count down the verification code (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn