Code:
1 <template> 2 <view> 3 <button hover-class="none" id="code" @click="codeRandom" :disabled="yanDisable" title="点击更换验证码"> 4 <text>{{ codenum }}</text> 5 </button> 6 </view> 7 </template>
. 1 < Script > 2 Export default { . 3 Data () { . 4 return { . 5 code: '' , . 6 codeNum: '' . 7 }; . 8 }, . 9 Methods: { 10 codeRandom () { . 11 the this .code = '' ; 12 is the this .codenum = '' ; 13 is var CodeLength = . 4 ; // verification code length 14 var random = [ 15 0, 16 1, 17 2, 18 3, 19 4, 20 5, 21 6, 22 7, 23 8, 24 9, 25 'A', 26 'B', 27 'C', 28 'D', 29 'E', 30 'F', 31 'G', 32 'H', 33 'I', 34 'J', 35 'K', 36 'L', 37 'M', 38 'N', 39 'O', 40 'P', 41 'Q', 42 'R', 43 'S', 44 'T', 45 'U', 46 'V', 47 'W', 48 'X', 49 'Y', 50 'Z' 51 ];0=Ivar(for52 israndom number// ; I < CodeLength; I ++ ) { 53 is var index = Math.floor (Math.random () * 36 ); // obtain index random number (0 ~ 35) 54 is the this .code + = Random [index]; // the index to obtain a random number is added to the code 55 } 56 is the this .codenum = the this .code; // the code value assigned codes 57 is }, 58 the validate () { 59 var inputCode = the this .user.code.toLowerCase (); //Enter the code acquired and converted to uppercase 60 IF (inputCode.length <= 0 ) { 61 is the this .tools.toastShow ( " Please enter the verification code! ' ); // pop up Please enter the verification code 62 is } the else IF (inputCode ! = the this .code.toLowerCase ()) { 63 is the this .tools.toastShow ( ' code is incorrect! ' ); // pop-up validation code input error 64 the this .codeRandom (); // refresh codes 65 the this . user.code = '' ; // clear the text box 66 } else { 67 // _this.successUrl = 'https://ping.jiaoyubao.cn/m/step1'; 68 this.goStep(); 69 } 70 }, 71 getHbNow() { 72 let _this = this; 73 let isTelRight = _this.tools.checkPhoneNum(_this.user.mobile); 74 let ajaxUrl = _this.$api.PostMessageCode.url + '&key={mobile:' + _this.user.mobile + '}' ; 75 IF ( ! {IsTelRight) 76 _this.tools.toastShow ( ' Enter the correct phone number ' ); 77 } the else { 78 _this.validate (); 79 } 80 } 81 } 82 }; 83 </ Script >
1 <style lang="scss"> 2 #code { 3 height: 86upx; 4 font-style: italic; 5 background: #d9d9da; 6 color: green; 7 border: 0; 8 padding: 4upx 6upx; 9 letter-spacing: 6upx; 10 font-weight: bolder; 11 } 12 </style>