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)

不言
Release: 2018-08-16 17:54:10
Original
3395 people have browsed it

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) {
    
  },

})
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template