axios delete方法怎么把参数放在body中

export function deleteFactory(factoryId) {
  return request({
    url: `factory/delete`,
    method: 'delete',
    data:{factoryId}
  })
}

request是封装的一个axios实例

    handleDelete($index, row) {
      const id = row.factoryId
      deleteFactory(id).then(res=>{
        console.log(res.data.success)
      })

    },

看到delete方法第二个参数是config,不懂这个config是什么意思
swagger中的调试
image.png

阅读 10.3k
1 个回答

放在body中简单,但要区分参数类型,比如是FormData还是json等

var axios = require('axios');
var qs = require('qs');

//1
var config = {
  method: 'delete',
  url: 'xxx',
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data : qs.stringify({'a': '1','b': '2' })
};

//2
var config = {
  method: 'delete',
  url: 'xxx',
  headers: { 
    'Content-Type': 'application/json'
  },
  data : JSON.stringify({"a":1,"b":2})
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题