axios传参
当后台springboot是post请求时,要用data来放参数
当后台springboot时get请求时,要用params来放参数.
post请求时:
axios({
//后端是post请求接口
url: `http://localhost:8080/reg`, data: {
username: ruleForm.name,
password: ruleForm.password,
email: ruleForm.email,
emCode: ruleForm.emailCode,
code: ruleForm.validateCode
}
}).then(res => {
console.log(res)
);
get请求时:
axios({
//后端是get请求接口
url: `http://localhost:8080/reg`, params: {
username: ruleForm.name,
password: ruleForm.password,
email: ruleForm.email,
emCode: ruleForm.emailCode,
code: ruleForm.validateCode
}
}).then(res => {
console.log(res)
);
在springboot中后台接受不到参数的原因是因为:
1.前端发送的数据格式是json,后端没有办法成功解析,所以就出现后端的参数没有办法获取前端参数造成数据无法获取
解决方法:
可以把axios中的post的数据用params来放置,这样后台就可以直接获取到前端传过去的数据了!!