提交 518a52b7 编写于 作者: X xiesi

增加登录信息验证和退出功能

上级 9cbaf485
......@@ -9,4 +9,32 @@ import 'element-plus/lib/theme-chalk/index.css';
import axios from 'axios'
import VueAxios from 'vue-axios'
createApp(App).use(store).use(router).use(ElementPlus).use(VueAxios, axios).mount("#app");
\ No newline at end of file
createApp(App).use(store).use(router).use(ElementPlus).use(VueAxios, axios).mount("#app");
router.beforeEach((to, from, next) => {
// to and from are both route objects. must call `next`.
if (to.meta.needLogin) {
console.log("hello");
axios.get("http://localhost:8070/login", {
withCredentials: true
})
.then((response) => {
if (response.data.usertype == '用户') {
//显示用户名
console.log(response.data.data.name);
next();
} else {
//当前为有课,不允许登录
next({
name: "Login",
query: {
redirect: to.meta.redirect
}
});
}
});
next();
} else {
next();
}
});
\ No newline at end of file
......@@ -8,6 +8,9 @@ const routes = [{
path: "/",
name: "Home",
component: Home,
meta: {
needLogin: true,
}
},
{
path: "/login",
......
......@@ -39,7 +39,7 @@
<el-main>
<el-button @click="onclickaxios"> hello</el-button>
<el-button @click="havelogin"> havelogin</el-button>
<el-button @click="gotologin"> gotologin</el-button>
<el-button @click="logout"> logout</el-button>
<el-button @click="gotologin11"> gotologin</el-button>
<router-link to="/Login">gotologin</router-link>
</el-main>
......@@ -99,6 +99,13 @@ export default {
console.log(response.data);
});
},
logout() {
this.axios
.post("http://localhost:8070/logout", {}, { withCredentials: true })
.then((response) => {
console.log(response.data);
});
},
},
data() {
return {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册