色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:9日期:2022-11-21 08:08:08

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

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

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

效果圖:

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

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

Html

<div class='login-form-item'> <el-form :model='ValidateForm' ref='ValidateForm' label- class='demo-ruleForm'> <el-form-itemprop='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-itemprop='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-itemprop='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 大家記得去下載

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

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 : ’賬號或密碼錯(cuò)誤,請重新輸入!’, type : ’error’ }) //清空 this.resetForm(’ValidateForm’) //刷新驗(yàn)證碼 this.$refs.switchSidentify.changeCode() } }) }else { this.$message({ message : ’驗(yàn)證碼輸入錯(cuò)誤,請重新輸入!’, 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è)置cookiesetCookie(c_name, c_pwd, exdays) { var exdate = new Date(); // 獲取時(shí)間 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();},// 讀取cookiegetCookie: 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; } } }},// 清除cookieclearCookie: 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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 特级av毛片免费观看 | 中国三级毛片 | 91热久久免费精品99 | 天天综合天天看夜夜添狠狠玩 | 国产精品高清视亚洲一区二区 | 亚洲视频一区在线 | 欧美日韩在线播一区二区三区 | 一级特级欧美aaaaa毛片 | 亚洲欧美精品一区天堂久久 | 精品成人一区二区三区免费视频 | 在线免费观看色 | 亚洲欧美日本人成在线观看 | 欧美亚洲国产成人高清在线 | 综合亚洲欧美日韩一区二区 | 韩国免费播放一级毛片 | 国产一区二区三区日韩欧美 | 99精品国产免费久久国语 | 国内自拍视频在线播放 | 成人毛片免费视频 | 久草在线观看首页 | 午夜两性视频 | 99精品国产综合久久久久 | 国产精品毛片久久久久久久 | 亚洲国产国产综合一区首页 | 国内精品免费一区二区观看 | 久久93精品国产91久久综合 | 国内精品久久久久久影院老狼 | 国产精品视频自拍 | 九九大香尹人视频免费 | 俄罗斯一级成人毛片 | 成人在线午夜 | 美女黄18 | 夜精品a一区二区三区 | 国产精品一级视频 | 国产在线精品一区二区不卡 | 国产一级网站 | 美女张开大腿让男人捅 | 一区二区三区高清不卡 | 日韩中文字幕视频在线 | 欧美色老头gay | 114一级毛片免费观看 |