添加请求接口

This commit is contained in:
2026-08-25 22:19:22 +08:00
parent ef50160ef5
commit 68ea2af952
3 changed files with 72 additions and 3 deletions
+12 -3
View File
@@ -36,6 +36,7 @@
</template>
<script>
import { login } from "@/utils/user";
export default {
name: "LoginPage",
data() {
@@ -49,9 +50,17 @@ export default {
// 登录接口接入后在这里提交账号和密码
// 这里模拟登录成功,直接跳转到聊天页面
if (this.username && this.password) {
this.$store.commit("SET_TOKEN", "mock-token");
this.$store.commit("SET_USERNAME", this.username);
this.$router.push("/chat");
login(this.username, this.password)
.then((response) => {
const token = response.data.token;
this.$store.commit("SET_TOKEN", token);
this.$store.commit("SET_USERNAME", this.username);
this.$router.push("/chat");
})
.catch((error) => {
console.error(error);
this.$message.error("登录失败,请检查账号和密码");
});
} else {
this.$message.error("请输入账号和密码");
}