晚上路由守护,在router.js
This commit is contained in:
@@ -81,7 +81,6 @@ export default {
|
||||
password:this.loginForm.password
|
||||
}
|
||||
}).then(res=>{
|
||||
console.log(res.data);
|
||||
if(res.data.code===200){
|
||||
this.$router.push('/home')
|
||||
ElNotification({
|
||||
@@ -149,4 +148,4 @@ export default {
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
@@ -107,12 +107,14 @@ export default {
|
||||
mounted(){
|
||||
axios.get("/api/v1/user/session").then(res => {
|
||||
if (res.data.code === 200) {
|
||||
console.log(res)
|
||||
this.username = res.data.data.username;
|
||||
this.role = res.data.data.role;
|
||||
//反正Navbar每次都要请求,直接在这请求session,然后写入cookie就好了
|
||||
localStorage.setItem('token',res.data.data.token);
|
||||
|
||||
}
|
||||
}).catch(err => {});
|
||||
//请求不到就删除token,防止变量出现还有遗留的情况,非常号解决方案
|
||||
}).catch(err => {localStorage.removeItem('token');});
|
||||
},
|
||||
|
||||
|
||||
|
@@ -65,7 +65,6 @@ export default {
|
||||
mounted(){
|
||||
axios.get("/api/v1/user/session").then(res => {
|
||||
if (res.data.code === 200) {
|
||||
console.log(res)
|
||||
this.username = res.data.data.username;
|
||||
this.role = res.data.data.role;
|
||||
|
||||
|
@@ -158,6 +158,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
//虽然已经路由守护了,但是再来一层防止越权
|
||||
axios.get('/api/v1/user/challenges/all').catch(function (error) {
|
||||
if (error.response.status == 400) {
|
||||
ElNotification.error({
|
||||
@@ -336,4 +337,4 @@ export default {
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user