今天寫了一個(gè)簡單的驗(yàn)證,本來前面用的組件,但是感覺寫的組件在此項(xiàng)目不是很好用,由于用到的地方比較少,所以直接寫在了頁面中。
<p> <p class="fl"> <input name="phone" type="number" placeholder="手機(jī)號(hào)" v-model="phone"/> <button type="button" :disabled="disabled" @click="sendcode" class="btns">{{btntxt}}</button> </p> <p class="fl" style="margin-left: 20px;"> <input type="text" placeholder="驗(yàn)證碼"/> </p> </p> <input type="button" value="查詢" class="btns search" @click="query"/>
這里是script里的內(nèi)容
export default { data: function () { return { disabled:false, time:0, btntxt:"獲取驗(yàn)證碼", formMess:{ email:this.email, phone:this.phone } } }, mounted: function () { }, methods:{ //驗(yàn)證手機(jī)號(hào)碼部分 sendcode(){ var reg=11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/; //var url="/nptOfficialWebsite/apply/sendSms?mobile="+this.ruleForm.phone; if(this.phone==''){ alert("請(qǐng)輸入手機(jī)號(hào)碼"); }else if(!reg.test(this.phone)){ alert("手機(jī)格式不正確"); }else{ this.time=60; this.disabled=true; this.timer(); /*axios.post(url).then( res=>{ this.phonedata=res.data; })*/ } }, timer() { if (this.time > 0) { this.time--; this.btntxt=this.time+"s后重新獲取"; setTimeout(this.timer, 1000); } else{ this.time=0; this.btntxt="獲取驗(yàn)證碼"; this.disabled=false; } }, query(){ var formMess=this.formMess Axios.post(api+"/order/select/reception", formMess) .then(function (res) { if(res.data.code==200){ console.log(res.data.data); this.productResult=res.data.data; this.productResult.length=3; }else if(res.data.code==400){ alert(res.data.message) } }.bind(this)) }, //郵箱驗(yàn)證 sendEmail(){ var regEmail= /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; if(this.email==''){ alert("請(qǐng)輸入郵箱"); }else if(!regEmail.test(this.email)){ alert("郵箱格式不正確"); } } } }
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注Gxl網(wǎng)其它相關(guān)文章!
推薦閱讀:
vue+axios表單中上傳圖片步驟詳解
axios發(fā)送post請(qǐng)求提交圖片表單步驟詳解
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com