添加请求接口
This commit is contained in:
@@ -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("请输入账号和密码");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user