<view class="list">
<text class="tit">验证码</text>
<u-input v-model="code" placeholder='请输入验证码'/>
<u-toast ref="uToast"></u-toast>
<u-verification-code :seconds="seconds" ref="uCode" @change="codeChange" start-text="获取验证码"></u-verification-code>
<view style="color: #5FC484;" @tap="getCode">{{tips}}</view>
</view>
code:'',
tips:'',
seconds:60,
codeChange(text) {
this.tips = text;
},
getCode() {
if( !this.$u.test.mobile(this.phone) ) return this.$alert.fail('请输入正确的手机号')
if (this.$refs.uCode.canGetCode) {
let data = {state: 1,phone: this.phone}
this.$u.api.sendSms(data).then(res => {
console.log(res)
if(res.code == 200){
uni.hideLoading();
this.$u.toast('验证码已发送');
this.$refs.uCode.start();
}else{
this.$alert.fail('发送失败,请重试')
}
})
} else {
this.$u.toast('倒计时结束后再发送');
}
},