vue 實現(xiàn)通過手機發(fā)送短信驗證碼注冊功能
更新時間:2018年04月19日 10:29:42 作者:簡簡單單的我
這篇文章主要介紹了vue 實現(xiàn)通過手機發(fā)送短信驗證碼注冊功能的相關(guān)資料,需要的朋友可以參考下
效果如下:

代碼如下:
template代碼:
<el-main>
<el-form
:model="ReginForm"
ref="ReginForm"
:rules="rule"
class="regform"
label-width="0">
<h3 class="login-text">手機注冊</h3>
<el-form-item prop="tel">
<el-input
type="text"
v-model.number="ReginForm.tel"
placeholder="手機號碼">
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
type="password"
v-model="ReginForm.password"
placeholder="密碼">
</el-input>
</el-form-item>
<div>
<input class="auth_input" type="text" v-model="verification" placeholder="輸入驗證碼" />
<span v-show="sendAuthCode" class="auth_text auth_text_blue" @click="getAuthCode">獲取驗證碼</span>
<span v-show="!sendAuthCode" class="auth_text"> <span class="auth_text_blue">{{auth_time}} </span> 秒之后重新發(fā)送驗證碼</span>
</div>
<el-form-item >
<el-button
type="success"
class="submitBtn"
round
@click.native.prevent="submit"
:loading="logining">
注冊
</el-button>
<hr>
<p>已經(jīng)有賬號,馬上去<span class="to" @click="tologin">登錄</span></p>
</el-form-item>
</el-form>
</el-main>
</template>
script 代碼如下
export default {
data () {
let confirmpasswordCheck = (rule, value, callback) => {
if (value === '') {
return callback(new Error('密碼是必須的'))
} else {
return callback()
}
}
let telCheck = (rule, value, callback) => {
if (value === '') {
return callback(new Error('電話號碼是必須的'))
} else if (!Number.isInteger(value)) {
return callback(new Error('電話號碼必須是數(shù)字'))
} else if (value.toString().length !== 11) {
return callback(new Error('電話號碼必須是11位數(shù)字'))
} else {
callback()
}
}
return {
ReginForm: {
password: '',
tel: '',
},
logining: false,
sendAuthCode:true,/*布爾值,通過v-show控制顯示‘獲取按鈕'還是‘倒計時' */
auth_time: 0, /*倒計時 計數(shù)器*/
verification:"",//綁定輸入驗證碼框框
rule: {
password: [
{
required: true,
message: '密碼是必須的!',
trigger: 'blur'
}
],
tel: [
{
required: true,
validator: telCheck,
trigger: 'blur'
}
],
}
}
},
methods: {
// 驗證
getAuthCode:function () {
const verification =this.ReginForm.tel;
const url = " "
console.log("url",url);
this.$http.get(url).then(function (response) {
console.log("請求成功",response)
}, function (error) {
console.log("請求失敗",error);
})
this.sendAuthCode = false;
//設(shè)置倒計時秒
this.auth_time = 10;
var auth_timetimer = setInterval(()=>{
this.auth_time--;
if(this.auth_time<=0){
this.sendAuthCode = true;
clearInterval(auth_timetimer);
}
}, 1000);
},
// 封裝注冊發(fā)送請求方法
thisAjax(){
const passwordData=this.ReginForm.password;
const phoneData =this.ReginForm.tel;
const mCodeData=this.verification;
// 手機注冊
//emulateJSON:true設(shè)置后post可跨域
const url = " 填接口"
this.$http.post(url,{填傳入的參數(shù)},{emulateJSON:true}).then(function (response)
{
//登錄后跳轉(zhuǎn)的頁面
this.$router.push('/');
}, function (error) {
alert("請求失敗",error);
})
},
// ...
submit () {
this.$refs.ReginForm.validate(valid => {
if (valid) {
this.logining = true
this. thisAjax();
console.log('開始寫入后臺數(shù)據(jù)!')
} else {
console.log('submit err')
}
})
},
reset () {
this.$refs.ReginForm.resetFields()
},
tologin () {
//已經(jīng)注冊過跳轉(zhuǎn)到登入界面
this.$router.push('/phoneLogin')
}
}
}
</script>
style代碼如下:
.regform {
margin: 20px auto;
width: 310px;
background: #fff;
box-shadow: 0 0 10px #B4BCCC;
padding: 30px 30px 0 30px;
border-radius: 25px;
}
.submitBtn {
width: 65%;
}
.to {
color: #FA5555;
cursor: pointer;
}
.auth_input{
width:140px;
height:38px;
margin-bottom:20px;
border:1px solid #DCDFE6;
/* color:red; */
padding-left:10px;
border-radius: 8%;
}
.regform[data-v-92def6b0]{
width:370px;
min-height: 440px;
}
.login-text{
text-align: center;
margin-bottom:20px;
}
</style>
總結(jié)
以上所述是小編給大家介紹的vue 實現(xiàn)通過手機發(fā)送驗證碼注冊功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
關(guān)于vue 的slot分發(fā)內(nèi)容 (多個分發(fā))
這篇文章主要介紹了關(guān)于vue 的slot分發(fā)內(nèi)容 (多個分發(fā)),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03
Vue CLI項目 axios模塊前后端交互的使用(類似ajax提交)
這篇文章主要介紹了Vue-CLI項目-axios模塊前后端交互的使用詳解(類似ajax提交),本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09
vue3 添加編輯頁使用 cron 表達式生成方法小結(jié)
這篇文章主要介紹了vue3 添加編輯頁使用 cron 表達式生成方法小結(jié),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-12-12

