日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > vue >内容正文

vue

Vue后台管理系统实现登录功能

發(fā)布時(shí)間:2025/3/21 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue后台管理系统实现登录功能 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

登錄頁面

vuex

router.js

main.js設(shè)置全局

退出功能刪除token 清空localStorage

顯示用戶名


鍵盤事件

** 記住密碼操作( 讀存取cookie與調(diào)后端數(shù)據(jù)無關(guān) 提交按鈕中操作 )**

點(diǎn)擊事件

// 登錄調(diào)接口handleSubmit(name) {// 判斷單選框是否被選中if (this.single == true) {console.log("checked == true");//傳入賬號(hào)名,密碼,和保存天數(shù)7天this.setCookie(this.formInline.account, this.formInline.password, 7);} else {console.log("清空Cookie");//清空Cookiethis.clearCookie();}if (!this.formInline.account && !this.formInline.password) {this.$Message.error("請輸入用戶名和密碼");} else if (!this.formInline.account) {this.$Message.error("請輸入用戶名");} else if (!this.formInline.password) {this.$Message.error("請輸入密碼");} else {this.$refs[name].validate(valid => {let val = {account: this.formInline.account,password: this.formInline.password};if (valid) {this.$ajax.post("/api/login", val).then(res => {if (res.data.code == 200) {this.initUserInfo();this.$Message.success({content: "登陸成功",duration: 0.3});} else {this.$Message.error("用戶名不存在,或密碼錯(cuò)誤");}});} else {return false;}});}},//獲取用戶信息initUserInfo() {this.$ajax.get("/api/getUserInfo").then(res => {const userInfo = res.data.data;// // this.form.username = userInfo.account;localStorage.setItem("userInfo", this.formInline.account);this.$store.commit("changeUserInfo", JSON.stringify(userInfo));this.$router.push({ path: "/tabbar" });this.$Message.success({content: "登陸成功",duration: 0.3});});},

設(shè)置cookie

//設(shè)置cookiesetCookie(c_name, c_pwd, exdays) {var exdate = new Date(); //獲取時(shí)間exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); //保存的天數(shù)//字符串拼接cookiewindow.document.cookie ="userName" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();window.document.cookie ="userPwd" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();},

讀取cookie

//讀取cookiegetCookie: function() {if (document.cookie.length > 0) {var arr = document.cookie.split("; "); //這里顯示的格式需要切割一下自己可輸出看下for (var i = 0; i < arr.length; i++) {var arr2 = arr[i].split("="); //再次切割//判斷查找相對應(yīng)的值if (arr2[0] == "userName") {this.formInline.account = arr2[1]; //保存到保存數(shù)據(jù)的地方 用戶名} else if (arr2[0] == "userPwd") {this.formInline.password = arr2[1]; //保存到保存數(shù)據(jù)的地方 密碼}}}},

清除cookie

//清除cookieclearCookie: function() {this.setCookie("", "", -1); //修改2值都為空,天數(shù)為負(fù)1天就好了}

mounted調(diào)用

mounted() {this.getCookie();調(diào)用}

總結(jié)

以上是生活随笔為你收集整理的Vue后台管理系统实现登录功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。