axios預設傳送post請求時候引數是json形式傳遞到後臺,後臺(SpringMvc)需要透過添加註解@RequestBody對映到物件的方式來接收,後臺開發人員認為我就2個引數,懶得再封裝個物件了,讓前端同事直接透過表單的形式傳遞。於是就有了如下解決辦法:
const form = new FormData();
form.append("username", this.username);
form.append("password", this.password);
form.append("rememberMe", this.rememberMe+"");
const data = await instance.post("/auth/authorize", new URLSearchParams(form));
axios
.post(process.env.BASE_API_LOGIN + "/auth/authorize", new URLSearchParams(form))
.then(function (response) {
console.log(response.data);
});
axios預設傳送post請求時候引數是json形式傳遞到後臺,後臺(SpringMvc)需要透過添加註解@RequestBody對映到物件的方式來接收,後臺開發人員認為我就2個引數,懶得再封裝個物件了,讓前端同事直接透過表單的形式傳遞。於是就有了如下解決辦法:
const form = new FormData();
form.append("username", this.username);
form.append("password", this.password);
form.append("rememberMe", this.rememberMe+"");
const data = await instance.post("/auth/authorize", new URLSearchParams(form));
axios
.post(process.env.BASE_API_LOGIN + "/auth/authorize", new URLSearchParams(form))
.then(function (response) {
console.log(response.data);
});