欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue前端實現(xiàn)login頁登陸驗證碼代碼示例

 更新時間:2024年05月03日 08:16:18   作者:Yoga99  
現(xiàn)在我們管理后臺有個需求,就是登錄頁面需要獲取驗證碼,用戶可以輸入驗證碼后進行登錄,這篇文章主要給大家介紹了關(guān)于vue前端實現(xiàn)login頁登陸驗證碼的相關(guān)資料,需要的朋友可以參考下

實現(xiàn)效果

// template
<el-form :model="loginForm" :rules="fieldRules" ref="loginForm" label-position="left" label-width="0px" class="login-container">
        <span class="tool-bar"></span>
        <h2 class="title">用戶登陸</h2>
        <el-form-item prop="account">
          <el-input type="text" v-model.trim="loginForm.account" auto-complete="false" placeholder="賬號"></el-input>
        </el-form-item>
        <el-form-item prop="password" class="item-m10">
          <el-input type="password" v-model.trim="loginForm.password" auto-complete="false" placeholder="密碼"></el-input>
        </el-form-item>
        <el-form-item prop="code" align="left" style="margin-top: 20px">
          <el-input v-model="loginForm.code" style="width: 170px" placeholder="驗證碼,點擊圖片刷新"></el-input>
          <el-tag class="login-tag-code" @click="getCode">{{ viewCode }}</el-tag>
        </el-form-item>
        <div class="checked-item">
          <el-checkbox v-model="checked">記住密碼</el-checkbox>
        </div>
        <el-form-item style="width: 100%" class="btn-item">
          <el-button style="width: 100%" @click.native.prevent="loginSubmit" :loading="loading">登錄</el-button>
 </el-form-item>


// js
// ---------分割線

  data () {
    return {
      viewCode: '',
      loginForm: {
        account: '',
        password: '',
        src: '',
        code: ''
      },
      fieldRules: {
        account: [{ required: true, message: '請輸入賬號', trigger: 'blur' }],
        password: [{ required: true, message: '請輸入密碼', trigger: 'blur' }]
      },
      checked: false,
      // 加載中的標(biāo)志
      loading: false
    }
  },


// ------ 分割線


  methods: {
    loginSubmit () {
      if (!this.loginForm.account || !this.loginForm.password) {
        this.$message.error('賬號或密碼不能為空!')
        return
      }
      if (!this.loginForm.code || this.loginForm.code !== this.viewCode) {
        this.$message.error('驗證碼不正確!')
        return
      }
      this.loading = true
      let userInfo = {
        account: this.loginForm.account,
        password: this.loginForm.password
      }
      //登陸接口
      this.$api.login
        .login(userInfo)
        .then((res) => {
            if (this.checked) {
              let rememberInfo = JSON.stringify({ ...userInfo })
              localStorage.setItem('rememberInfo', rememberInfo) // 記住密碼時 保存login
            } else {
              localStorage.removeItem('rememberInfo')
            }
            this.$router.push('/') // 登錄成功,跳轉(zhuǎn)到主頁 
            this.loading = false
        })
        .catch((err) => {
          this.$message({ message: err.message, type: 'error' })
        })
    },

  //獲取驗證碼
    getCode () {
      this.viewCode = ''
      let codeString = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
      let codeArray = codeString.split('')
      let num = codeArray.length
      let newCodeArray = []
      for (let i = 0; i < 5; i++) {
        let index = Math.floor(Math.random() * num)
        newCodeArray.push(codeArray[index])
      }
      this.viewCode = newCodeArray.join('')
    },
  },
  mounted () {
    this.getCode()
    if (localStorage.getItem('rememberInfo')) {
      // 有上次登錄信息 顯示上次登錄
      let rememberData = JSON.parse(localStorage.getItem('rememberInfo'))
      const { account, password } = rememberData
      this.loginForm.account = account
      this.loginForm.password = password
    }
  }

樣式代碼省略。。。

總結(jié)

到此這篇關(guān)于vue前端實現(xiàn)login頁登陸驗證碼的文章就介紹到這了,更多相關(guān)vue登陸頁驗證碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue事件總線的使用問題及解讀

    Vue事件總線的使用問題及解讀

    這篇文章主要介紹了Vue事件總線的使用問題及解讀,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • Vue3如何獲取proxy對象的值而不是引用的方式

    Vue3如何獲取proxy對象的值而不是引用的方式

    這篇文章主要介紹了Vue3如何獲取proxy對象的值而不是引用的方式,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-10-10
  • Vue和Bootstrap的整合思路詳解

    Vue和Bootstrap的整合思路詳解

    這篇文章主要介紹了Vue和Bootstrap的整合思路詳解,需要的朋友可以參考下
    2017-06-06
  • 淺析在Vue中watch使用的必要性及其優(yōu)化

    淺析在Vue中watch使用的必要性及其優(yōu)化

    這篇文章主要來和大家深入討論一下在Vue開發(fā)中是否有必要一定用watch,如果換成watcheffect會如何,文中的示例代碼講解詳細,需要的可以參考下
    2023-12-12
  • vue實現(xiàn)短信驗證碼輸入框

    vue實現(xiàn)短信驗證碼輸入框

    這篇文章主要為大家詳細介紹了vue實現(xiàn)短信驗證碼輸入框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • Vue實現(xiàn)可移動水平時間軸

    Vue實現(xiàn)可移動水平時間軸

    這篇文章主要為大家詳細介紹了Vue實現(xiàn)可移動水平時間軸,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • Vue transition實現(xiàn)點贊動畫效果的示例

    Vue transition實現(xiàn)點贊動畫效果的示例

    點贊動畫是網(wǎng)頁評論中常見的功能,本文將介紹如何用vue實現(xiàn)這一效果。點贊時愛心縮小變大,變大時略微大一點再變正常,取消點贊時愛心無動畫,同時數(shù)字滾動,+1 時向上滾動,-1 時向下滾動
    2021-05-05
  • vue-cli4使用全局less文件中的變量配置操作

    vue-cli4使用全局less文件中的變量配置操作

    這篇文章主要介紹了vue-cli4使用全局less文件中的變量配置操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • vue3路由router.push的使用以及問題分析

    vue3路由router.push的使用以及問題分析

    頁面跳轉(zhuǎn)有很多方法,本次使用的是?vue-router,但卻在使用?router.push?的時候遇到了點麻煩,所以記錄下來,希望可以幫助有需要的人
    2023-09-09
  • vue+element表格實現(xiàn)多層數(shù)據(jù)的嵌套方式

    vue+element表格實現(xiàn)多層數(shù)據(jù)的嵌套方式

    這篇文章主要介紹了vue+element表格實現(xiàn)多層數(shù)據(jù)的嵌套方式,具有很好的參考價值。希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09

最新評論