【vue.js--axios.post发送表单数据传给后台是空对象的问题解决】

此处用对象形式传数据,而官方文档中说明了:默认情况下,会把数据对象转成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');
				});
			},

只需要加上声明头就可以,你可以在全局加,也可以在方法里加。

猜你喜欢

转载自blog.csdn.net/Mrchai521/article/details/105007375