提交 149b04f8 编写于 作者: 谢斯 提交者: xiesi

当没有登录信息的时候 需要跳到登录界面

Signed-off-by: Nxiesi <305492881@qq.com>
上级 518a52b7
...@@ -14,22 +14,21 @@ createApp(App).use(store).use(router).use(ElementPlus).use(VueAxios, axios).moun ...@@ -14,22 +14,21 @@ createApp(App).use(store).use(router).use(ElementPlus).use(VueAxios, axios).moun
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// to and from are both route objects. must call `next`. // to and from are both route objects. must call `next`.
if (to.meta.needLogin) { if (to.meta.needLogin) {
console.log("hello");
axios.get("http://localhost:8070/login", { axios.get("http://localhost:8070/login", {
withCredentials: true withCredentials: true
}) })
.then((response) => { .then((response) => {
if (response.data.usertype == '用户') { console.log(response.data);
if (response.data.Code == 0) {
//显示用户名 //显示用户名
console.log(response.data.data.name); console.log(response.data.data.name);
next(); next();
} else { } else {
//当前为有课,不允许登录 //当前为有课,不允许登录
console.log("需要跳转到登录页面");
router.push("Login");
next({ next({
name: "Login", path: "Login",
query: {
redirect: to.meta.redirect
}
}); });
} }
}); });
......
...@@ -37,9 +37,11 @@ ...@@ -37,9 +37,11 @@
</el-header> </el-header>
<el-main> <el-main>
<el-button @click="onclickaxios"> hello</el-button> <el-button @click="onclickaxios"> login_post</el-button>
<el-button @click="havelogin"> havelogin</el-button> <el-button @click="havelogin"> login_get</el-button>
<el-button @click="logout"> logout</el-button> <el-button @click="logout"> logout</el-button>
<br>
<br>
<el-button @click="gotologin11"> gotologin</el-button> <el-button @click="gotologin11"> gotologin</el-button>
<router-link to="/Login">gotologin</router-link> <router-link to="/Login">gotologin</router-link>
</el-main> </el-main>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册