parent
0bf8e959dd
commit
e980cdc905
@ -0,0 +1,42 @@
|
||||
<template>
|
||||
<div>
|
||||
<form @submit.prevent="login">
|
||||
<input placeholder="用户名" v-model="formData.username" required />
|
||||
<input v-model="formData.password" type="password" placeholder="密码" />
|
||||
<button type="submit">登录</button>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
formData:{
|
||||
username: '',
|
||||
password: ''
|
||||
}
|
||||
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async login() {
|
||||
|
||||
const response = await axios.post('http://127.0.0.1:8000/register', this.formData);
|
||||
console.log(response.data); // 后端返回的数据
|
||||
|
||||
if(response.data.code === 200){
|
||||
alert("登录成功")
|
||||
}else if (response.data.code === 400){
|
||||
alert("密码错误")
|
||||
}else{
|
||||
alert("用户不存在")
|
||||
}
|
||||
// 根据后端返回判断是否登录成功
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7"
|
||||
}
|
||||
}
|
Loading…
Reference in new issue