问题

和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的网站)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐