登录后获取信息,用于判断登录后是否过期

This commit is contained in:
2026-09-12 15:51:53 +08:00
parent fe47a38a13
commit 60d7ecea5f
2 changed files with 10 additions and 1 deletions
+9
View File
@@ -19,6 +19,7 @@
</template> </template>
<script> <script>
import { getUserInfo } from "@/utils/user";
export default { export default {
name: "ChatPage", name: "ChatPage",
props: {}, props: {},
@@ -28,6 +29,14 @@ export default {
password: "", password: "",
}; };
}, },
created() {
getUserInfo().then(response => {
this.username = response.data.username;
}).catch(error => {
console.error(error);
this.$message.error("登录过期,请重新登录");
})
},
methods: { methods: {
handleLogout() { handleLogout() {
this.$store.commit("REMOVE_TOKEN", ''); this.$store.commit("REMOVE_TOKEN", '');
+1 -1
View File
@@ -12,7 +12,7 @@ export function login(data) {
// 获取用户信息 // 获取用户信息
export function getUserInfo() { export function getUserInfo() {
return request({ return request({
url: '/user/info', url: '/userInfo',
method: 'get' method: 'get'
}) })
} }