遇到的问题描述 :axios post 请求,后端接收不到参数。
我们的接口是java,用@RequestParam来接收前端的参数
解决方案:使用qs;axios中已经包含有qs,所以无需重新安装,直接引入就好
import Qs from 'qs'//引入qs
let chedata = {
data: encStr,
sign: md5.hexMD5(che),
timestamp: timestamp,
}
//chedata是我需要传递给后端的参数
console.log(Qs.stringify(chedata))
axios({
header: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
method:method || get,
url: baseUrl + url,
data:Qs.stringify(chedata),//在传参之前先用qs.stringify转化一下格式
responseType
}).then((response) => {
console.log(response)
success(response.data);
}).catch((err)=>{
console.log(err)
})
}
}