微信小程序手机号验证码登录的项目实现

本文主要介绍了微信小程序手机号验证码登录的项目实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

本文主要介绍了小程序手机号验证码登录,具体如下:

在这里插入图片描述

在这里插入图片描述

wxml:

 

js:

// pages/login/login.js import http from '../../http/api'; import env from '../../http/evn.js'; Page({ data: { phone: '', code: '', codename: '获取验证码', }, getPhoneValue: function (e) { this.setData({ phone: e.detail.value }) }, getCodeValue: function (e) { this.setData({ code: e.detail.value }) }, //获取验证码 getVerificationCode() { this.getCode(); var _this = this // _this.setData({ //   disabled: true // }) }, getCode: function () { console.log(this.data.phone, '手机号') var _this = this; var myreg = /^(14[0-9]|13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$$/; if (this.data.phone == "") { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 1000 }) return false; } else if (!myreg.test(this.data.phone)) { wx.showToast({ title: '请输入正确的手机号', icon: 'none', duration: 1000 }) return false; } else { _this.setData({ disabled: true }) http.sendsms({ data: { phone: this.data.phone }, success(res) { var bgColor = this.data.pageBackgroundColor == '#9db8db'; _this.setData({ pageBackgroundColor: bgColor //  iscode: res.data.data }) var num = 60; var timer = setInterval(function () { num--; if (num <= 0) { clearInterval(timer); _this.setData({ codename: '重新发送', disabled: false }) } else { _this.setData({ codename: num + "s" }) } }, 1000) } }) } }, }) 

到此这篇关于微信小程序手机号验证码登录的项目实现的文章就介绍到这了,更多相关小程序手机号验证码登录内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是微信小程序手机号验证码登录的项目实现的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程