还是有问题,不过现在后端可以正常收到username和password

This commit is contained in:
MiLla 2024-06-25 14:54:39 +08:00
parent d5611562e6
commit 1452208822
2 changed files with 18 additions and 4 deletions

View File

@ -2,11 +2,19 @@ import axios from "axios";
export default { export default {
login(username, password, apiUrl="http://localhost:8080"){ login(username, password, apiUrl="http://localhost:8080"){
return axios.get(`/checkLogin`, {username:username, password:password}) const url = `${apiUrl}/users/checkLogin`
const data = {
username: username,
password: password
};
return axios.post(url, data)
.then(response => { .then(response => {
alert("hahaha"); alert(">login方法中<");
// 处理登录成功的逻辑 alert(response.data);
return response.data; return response.data;
}); });
},
register(){
//跳转逻辑
} }
} }

View File

@ -7,6 +7,7 @@
<el-input v-model="username" placeholder="pls enter the username"></el-input> <el-input v-model="username" placeholder="pls enter the username"></el-input>
<el-input v-model="password" placeholder="pls enter the password"></el-input> <el-input v-model="password" placeholder="pls enter the password"></el-input>
<el-button type="success" @click="handleLogin">LOGIN</el-button> <el-button type="success" @click="handleLogin">LOGIN</el-button>
<el-button type="success" @click="handleRegister">REGISTER</el-button>
</template> </template>
<script> <script>
@ -22,7 +23,12 @@
},methods:{ },methods:{
handleLogin(){ handleLogin(){
authenticationService.login(this.username,this.password).then(res=>{ authenticationService.login(this.username,this.password).then(res=>{
alert(res); alert("login方法调用完毕");
alert(res.data);
});
},handleRegister(){
authenticationService.register(this.username,this.password).then(res=>{
alert(res);
}); });
} }
} }