vue 從后端拿到驗證碼並點擊刷新


驗證碼登錄的實現思路
1.前端從后端拿到驗證碼圖片
2.輸入驗證碼進行登錄
3.后端拿到驗證碼進行比對,正確登錄成功。

前端請求驗證碼直接寫在img標簽中即可,不必單獨發送axios請求

 

 

// template
           <a-input
              style="width:60%"
              size="large"
              type="text"
              placeholder="驗證碼: "
              v-decorator="[
                'verification',
                {rules: [{ required: true, message: '請輸入驗證碼' }], validateTrigger: 'change'}
              ]"
            >
              <a-icon slot="picture" type="user" :style="{ color: 'rgba(0,0,0,.25)' }"/>
            </a-input>
            <img style="float:right;height:40px" @click="replace" :src="imgCode" alt="">

//js
            data () {
               retrun {
                 imgCode: 'http://192.168.1.119:8000/cms/getCaptcha'
               }
            }
            replace () {
              const num = Math.ceil(Math.random() * 10) // 生成一個隨機數(防止緩存)
              this.imgCode = 'http://192.168.1.119:8000/cms/getCaptcha?' + num
            }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM