Skip to content

Commit ee09a97

Browse files
author
v-anzha
committed
vuex+jwt login auth
1 parent 9b30059 commit ee09a97

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/api/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import router from "../router.js";
33

44
// 配置API接口地址
55
var root = "http://localhost:58427/api";
6-
var root1 = "http://123.206.33.109:8012/api";
6+
var root1 = "http://123.206.33.109:8018/api";
77
// 引用axios
88
var axios = require("axios");
99
// 自定义判断元素类型JS

src/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const router = new Router({
5353

5454
router.beforeEach((to, from, next) => {
5555
if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
56-
if (window.localStorage.Token) { // 通过vuex state获取当前的token是否存在
56+
if (window.localStorage.Token&&window.localStorage.Token.length>=128) { // 通过vuex state获取当前的token是否存在
5757
next();
5858
}
5959
else {

src/views/Login.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<el-row type="flex" justify="center">
3-
<el-form ref="loginForm" :model="user" :rules="rules" status-icon label-width="50px">
3+
<el-card v-if="isLogin">
4+
欢迎:admins
5+
<br>
6+
<br>
7+
<el-button type="primary" icon="el-icon-upload" @click="loginOut">退出登录</el-button>
8+
</el-card>
9+
<el-form v-else ref="loginForm" :model="user" :rules="rules" status-icon label-width="50px">
410
<el-form-item label="账号" prop="name">
511
<el-input v-model="user.name"></el-input>
612
</el-form-item>
@@ -50,16 +56,27 @@ export default {
5056
return false;
5157
}
5258
});
53-
}
59+
},
60+
loginOut(){
61+
this.isLogin=false;
62+
window.localStorage.setItem("Token","");
63+
}
5464
},
5565
data() {
5666
return {
67+
isLogin:false,
5768
user: {},
5869
rules: {
5970
name: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
6071
pass: [{ required: true, message: "密码不能为空", trigger: "blur" }]
6172
}
6273
};
63-
}
74+
},
75+
created() {
76+
if (window.localStorage.Token&&window.localStorage.Token.length>=128){
77+
this.isLogin=true;
78+
}
79+
}
80+
6481
};
6582
</script>

0 commit comments

Comments
 (0)