最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue+element+cookie記住密碼功能的簡單實(shí)現(xiàn)方法

 更新時間:2020年09月20日 09:09:14   作者:WByangqq  
這篇文章主要給大家介紹了Vue+element+cookie記住密碼功能的簡單實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

實(shí)現(xiàn)功能:

1、登錄時勾選記住密碼,用cookie保存賬號和密碼并對密碼進(jìn)行兩次加密處理(純前端),下次登錄自動輸入賬號密碼

2、登錄時不勾選,清空cookie,下次登錄需要輸入

效果圖:

=============================================================================================================================================================================================

Html

 <div class="login-form-item">
     <el-form :model="ValidateForm" ref="ValidateForm" label-width="100px" class="demo-ruleForm">
      <el-form-item

        prop="username"
        :rules="[{ required: true, message: '用戶名不能為空'}
      ]">
       <span><i class="el-icon-user"></i></span><el-input type="username" v-model.number="ValidateForm.username" autocomplete="off" clearable placeholder="用戶名"></el-input>
      </el-form-item>
      <br>
      <el-form-item

        prop="password"
        :rules="[{ required: true, message: '密碼不能為空'},
      ]">
       <span><i class="el-icon-lock"></i></span><el-input type="password" v-model.number="ValidateForm.password" autocomplete="off" clearable show-password placeholder="密碼"></el-input>
      </el-form-item>
      <br>
      <el-form-item

        prop="sidentify"
        :rules="[
{ required: true, message: '驗(yàn)證碼不能為空'},]"
      >
       <el-row class="sidentify">
        <el-col :span="21">
         <el-input type="age" v-model="ValidateForm.sidentify" autocomplete="off" placeholder="驗(yàn)證碼"></el-input>
        </el-col>
        <el-col :span="3" class="sidentify sidentify-img">
         <sidentify :changeCode.sync='identifyCode' ref="switchSidentify"></sidentify>
        </el-col>
       </el-row>
      </el-form-item>
      <el-form-item>
       <el-checkbox v-model="checked" class="sidentify">記住密碼</el-checkbox>
      </el-form-item>
      <el-form-item>
       <el-button type="primary" @click="submitForm('ValidateForm')" class="login-btn">登錄</el-button>
      </el-form-item>
     </el-form>
    </div>

加密方法我用的base64和CryptoJS 大家記得去下載

js部分:

登錄

// 登錄
submitForm(formName) {
 this.$refs[formName].validate((valid) => {
  if (valid) {
   let username=this.ValidateForm.username;
   let pwd=this.ValidateForm.password;
   let sidentify=this.ValidateForm.sidentify;
   // 驗(yàn)證碼通過
   if (sidentify == this.identifyCode){
    this.request.post(this.api.login.logindo,{username:username,pwd:pwd}).then((res)=>{
     console.log(res);
     if (res.data.code == 200){
      this.$message({
       message : '登錄成功!',
       type : 'success'
      })
      //調(diào)用check選中方法
      this.checkedPwd(username,pwd)
      this.$router.push({name:'Home'})
     }else {
      this.$message({
       message : '賬號或密碼錯誤,請重新輸入!',
       type : 'error'
      })
      //清空
      this.resetForm('ValidateForm')
      //刷新驗(yàn)證碼
      this.$refs.switchSidentify.changeCode()
     }
    })
   }else {
    this.$message({
     message : '驗(yàn)證碼輸入錯誤,請重新輸入!',
     type : 'error'
    })
    this.$refs.switchSidentify.changeCode()
    this.resetForm('ValidateForm')
   }
  } else {
   return false;
  }
 });
},

check方法:

checkedPwd(username,pwd){
 // 記住密碼進(jìn)行cookie存儲和密碼加密
 if (this.checked){
  // base64 加密
  let base64Pwd=Base64.encode(pwd);
  // Encrypt 加密
  let cryptoJsPwd=CryptoJS.AES.encrypt(base64Pwd,key).toString()
  // 賬號密碼保存天數(shù)
  this.setCookie(username,cryptoJsPwd,7)
 }else{
  // 清空
  this.clearCookie()
 }
},

設(shè)置讀取和清空cookie

// 設(shè)置cookie
setCookie(c_name, c_pwd, exdays) {
 var exdate = new Date(); // 獲取時間
 exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); // 保存的天數(shù)
 // 字符串拼接cookie
 window.document.cookie = "username" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();
 window.document.cookie = "password" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();
},
// 讀取cookie
getCookie: function() {
 if (document.cookie.length > 0) {
  //checked為true
  this.checked=true
  var arr = document.cookie.split('; ');
  for (var i = 0; i < arr.length; i++) {
   var arr2 = arr[i].split('=');
   if (arr2[0] == 'username') {
    this.ValidateForm.username = arr2[1];
   } else if (arr2[0] == 'password') {
    // Decrypt 解密
    let bytes = CryptoJS.AES.decrypt(arr2[1],key)
    let originalText=bytes.toString(CryptoJS.enc.Utf8)
    // base64解密
    let pwd=Base64.decode(originalText)
    this.ValidateForm.password = pwd;
   }
  }
 }
},
// 清除cookie
clearCookie: function() {
 this.setCookie("", "", -1); // 修改2值都為空,天數(shù)為負(fù)1天就好了
},

一定要創(chuàng)建后讀取cookie

created () {
 this.getCookie()
},

總結(jié)

到此這篇關(guān)于Vue+element+cookie記住密碼功能的簡單實(shí)現(xiàn)方法文章就介紹到這了,更多相關(guān)Vue+element+cookie記住密碼功能內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • el-table表格排序(多列排序和遠(yuǎn)程排序)

    el-table表格排序(多列排序和遠(yuǎn)程排序)

    本文主要介紹了el-table表格排序(多列排序和遠(yuǎn)程排序),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • 解決axios post 后端無法接收數(shù)據(jù)的問題

    解決axios post 后端無法接收數(shù)據(jù)的問題

    今天小編就為大家分享一篇解決axios post 后端無法接收數(shù)據(jù)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • vue如何使用cookie、localStorage和sessionStorage進(jìn)行儲存數(shù)據(jù)

    vue如何使用cookie、localStorage和sessionStorage進(jìn)行儲存數(shù)據(jù)

    這篇文章主要介紹了vue如何使用cookie、localStorage和sessionStorage進(jìn)行儲存數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 圖文詳解如何在vue3+vite項(xiàng)目中使用svg

    圖文詳解如何在vue3+vite項(xiàng)目中使用svg

    SVG指可伸縮矢量圖形,用來定義用于網(wǎng)絡(luò)的基于矢量的圖形,下面這篇文章主要給大家介紹了關(guān)于如何在vue3+vite項(xiàng)目中使用svg的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • 在vue中配置不同的代理同時訪問不同的后臺操作

    在vue中配置不同的代理同時訪問不同的后臺操作

    這篇文章主要介紹了在vue中配置不同的代理同時訪問不同的后臺操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue3使用自定義指令實(shí)現(xiàn)el dialog拖拽功能示例詳解

    vue3使用自定義指令實(shí)現(xiàn)el dialog拖拽功能示例詳解

    這篇文章主要為大家介紹了vue3使用自定義指令實(shí)現(xiàn)el dialog拖拽功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Vue實(shí)現(xiàn)實(shí)時更新sessionStorage數(shù)據(jù)的示例代碼

    Vue實(shí)現(xiàn)實(shí)時更新sessionStorage數(shù)據(jù)的示例代碼

    這篇文章主要為大家詳細(xì)介紹了Vue如何實(shí)現(xiàn)實(shí)時更新sessionStorage數(shù)據(jù),文中的示例代碼講解詳細(xì),具有一定的參考價值,需要的可以參考一下
    2023-06-06
  • 基于vuejs+webpack的日期選擇插件

    基于vuejs+webpack的日期選擇插件

    這篇文章主要為大家詳細(xì)介紹了基于vuejs+webpack的日期選擇插件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • vue項(xiàng)目遇見事件冒泡該如何處理詳解

    vue項(xiàng)目遇見事件冒泡該如何處理詳解

    冒泡事件處理是由內(nèi)而外發(fā)生的,例如有兩個父子div,給他們分別寫上點(diǎn)擊事件,點(diǎn)擊子div先響應(yīng)的是子div,再是父div,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目遇見事件冒泡該如何處理的相關(guān)資料,需要的朋友可以參考下
    2023-04-04
  • 基于vue+h5實(shí)現(xiàn)車牌號輸入框功能(demo)

    基于vue+h5實(shí)現(xiàn)車牌號輸入框功能(demo)

    最近開發(fā)項(xiàng)目是學(xué)校校內(nèi)車輛超速方面的統(tǒng)計(jì)檢測方面的系統(tǒng),在開發(fā)過程中發(fā)現(xiàn)有個小功能,就是用戶移動端添加車牌號,剛開始想著輸入框,提交時正則效驗(yàn)一下格式,最后感覺不方便,所以就簡單自己手寫了一個H5車牌號軟鍵盤,對vue車牌號輸入框?qū)崿F(xiàn)代碼感興趣的朋友一起看看吧
    2025-03-03

最新評論

板桥市| 晋中市| 临邑县| 永川市| 缙云县| 高安市| 咸阳市| 读书| 瑞丽市| 黔江区| 兰州市| 沾化县| 宁津县| 永济市| 长海县| 吐鲁番市| 林口县| 紫云| 乡宁县| 宝兴县| 巨野县| 沈阳市| 杭锦后旗| 太仓市| 东台市| 丰县| 滨海县| 赣榆县| 达拉特旗| 靖州| 广南县| 新田县| 博罗县| 洛南县| 通州市| 文山县| 资中县| 嘉定区| 富宁县| 湖南省| 厦门市|