// 这里是一整个验证码框,验证码图标加输入框加获取验证码(显示倒计时框)
<view class="row between d-items-center b-b"> <view class="iconfont icon-suo" style="color: #FFFFFF; margin: 0 20upx;"> </view> <input type="number" value="" class="reg-input fill" placeholder="请输入验证码" placeholder-class="placeClass" v-model="code" /> <text class="y-z-m" @click="getYZM">{{ rTime }} <text v-if="btnState">s后重发</text> </text> </view>
data定义变量
rTime: '获取验证码', //获取按钮
btnState: false ,是否显示s后重发
methods方法 async getYZM() {
//这里验证手机号输入,data是需要的参数,在其他方法里定义的,返回这种的类似{phone: 133xxxxxxxx}
const data = this.getData('code');
if (!data) return;
if (this.rTime == '获取验证码') {
console.log(data);
//这里是通过data参数获取验证码
const res = await this.$request('member/GetVerify',data);
this.$util.msg(res.resultNote)
if (res.result == 0) {
//这里更改
this.rTime = 60;
this.btnState = true;
this.interval = setInterval(() => {
--this.rTime <= 0 ? (this.rTime = '获取验证码', clearInterval(this.interval), this.btnState = false) : 0
}, 1000)
}
}