此處用對象形式傳數據,而官方文檔中說明了:默認情況下,會把數據對象轉成JSON格式傳給服務端,傳的數據格式應該是字符串格式 name=cxf&gender=男
官方文檔:https://www.npmjs.com/package/axios
login(){
let { username,password } = this;
this.axios.post('/user/login.do',{
headers: { 'content-type': 'application/x-www-form-urlencoded' }
},
{
params: {username:username,password:password}
}).then((res)=>{
this.res = res;
this.$router.push('/index');
});
},
只需要加上聲明頭就可以,你可以在全局加,也可以在方法里加。