Axios 参数问题,只需要值的情况(不传对象)
问题和JAVA对接口,参数一直传不过去(前端报400错误,后端报传递的参数错误),header也改了,参数传不传字符串都不行代码如下:this.$axios.post('/api/chuli/deleteByIds',{ids: this.ids},{headers: {'Content-Type': 'application/json'}}).then((res) => {console.
·
问题
和JAVA 对接口,参数一直传不过去(前端报400错误,后端报传递的参数错误),header也改了,参数传不传字符串都不行
代码如下:
this.$axios.post('/api/chuli/deleteByIds',
{
ids: this.ids
},
{
headers: {
'Content-Type': 'application/json'
}
}).then((res) => {
console.log(res)
})
原因
最后,终于找到原因了,后端接口,不需要传递键值的形式,直接传数据就好
解决方案
this.$axios.post('/api/chuli/deleteByIds',this.ids,
{
headers: {
'Content-Type': 'application/json'
}
}).then((res) => {
console.log(res)
})
注意,post 方法的第二个参数,不是对象,直接传数据就好了
或者,使用 data 传递
this.$axios({
url: '/api/chuli/deleteByIds' ,
method: 'post',
headers: {
'Content-Type': 'application/json'
},
data:this.ids
}).then((res) => {
console.log(res)
})
同样注意,data 的值不是对象,直接写要传递的值即可
作者:doubleyong
公众号:bug收集
博客:bugshouji.com (专门解决与收集bug的网站)
更多推荐


所有评论(0)