Vue向后端传数据后端接收为null的解决方法

由于axios默认发送数据时,数据格式是Request Payload,而并非我们常用的Form Data格式,后端数据就为null,所以在发送之前,需要使用qs模块对其进行处理。

他们的格式:

Request Payload:http://localhost:8080/login?zh=123,pw=123
Form Data:http://localhost:8080/login,{zh=“123”,pw=“123”}

安装qs

npm install qs

mian.js中添加

import qs from 'qs'      //引入qs
Vue.prototype.$qs = qs

vue请求

axios.post('http://localhost:8080/manage/doctor/login.do',
		this.$qs.stringify({
		doctorName:this.form.username,
			password:this.form.password,
			// test:3,
		}) 
		)
		.then(response=>{
			 console.log(response);
		})
		//获取失败
		.catch(error=>{
			  console.log(error);
			  alert('网络错误,不能访问');
		})

我的后端用的java,给你们看下效果图吧:
在这里插入图片描述
在这里插入图片描述
感谢观看!

发布了80 篇原创文章 · 获赞 7 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_42332821/article/details/104790544