寫在前面
短信驗證現在做項目幾乎是必備技能,現在我幫我最近這個項目的這一功能實現分享給大家,希望有所幫助。
先上效果圖
html代碼
<view class="match-row form-item">
<view class="title">手機號</view>
<input placeholder-class="in-text" :disabled="IDNumber != ''?true:false" placeholder="請輸入手機號" v-model="Phone" @blur="checkPhone" />
<view class="checking" @tap="handleCode" v-if="IDNumber == ''">{{codeBtn}}</view>
</view>
<view class="match-row form-item" v-if="IDNumber == ''">
<view class="title">短信驗證碼</view>
<input class="input-text" v-model="code" placeholder="請輸入短信驗證碼" placeholder-class="in-text" type="text" />
</view>
js代碼
data() {
return {
Phone: '',
codeBtn: '獲取驗證碼',
code: '',
isClick2: true,
};
},
methods: {
//獲取驗證碼
handleCode() {
var that = this;
let count = 60;
if (that.Phone == '') {
uni.showToast({
title: '手機號不能爲空',
duration: 1000,
icon: 'none'
});
} else if (that.isClick2) {
that.isClick2 = false;
let timer = setInterval(function() {
count--;
that.codeBtn = '獲取中(' + count + ')';
if (count == 0) {
that.isClick2 = true;
clearInterval(timer)
that.codeBtn = '重新獲取';
}
}, 1000)
that.utils.sendRequest('/api/publicc/send_code', 'GET', {
mobile: that.Phone
}).then(function(res) {
if (res.data.code == 1) {
uni.showToast({
title: '已發送,請注意查收',
duration: 1000,
icon: 'none'
});
}
})
}
},
},
創作不易,點個贊吧!!
版權聲明:如無特殊說明,文章均爲本站原創,轉載請註明出處
本文鏈接:https://blog.csdn.net/wsad861512140