【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');
				});
			},

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

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
this.$Axios.post提交表单是指使用Axios库中的post方法来提交表单数据。在引用\[2\]和引用\[3\]中都提到了使用Axios库的post方法来发送POST请求。具体的使用方法是通过调用this.$axios.post(url, data)来发送POST请求,其中url是请求的地址,data是要发送表单数据。在引用\[2\]中的代码示例中,使用了this.axios.post("user_login.php", data)来提交表单数据。而在引用\[3\]中的代码示例中,使用了this.$axios.post('/user/login', this.$qs.stringify({ login_account: this.loginForm.username, password: this.loginForm.password, remark: this.checked === true ? 'autologin' : 'nocheck' }))来提交表单数据。所以,this.$Axios.post提交表单的具体实现可以参考这两个代码示例。 #### 引用[.reference_title] - *1* *2* [vue项目分析--this.$store.dispatch()&this.$store.commit()&vuex.store()](https://blog.csdn.net/weixin_46045444/article/details/120720528)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [axios发送post请求,提交表单数据](https://blog.csdn.net/weixin_30670925/article/details/98508087)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值