📜  在js中将formdata添加到axios请求 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:04.188000             🧑  作者: Mango

代码示例1
var bodyFormData = new FormData();

bodyFormData.append('userName', 'Fred');
bodyFormData.append('image', imageFile); 

axios({
  method: "post",
  url: "myurl",
  data: bodyFormData,
  headers: { "Content-Type": "multipart/form-data" },
})
  .then(function (response) {
    //handle success
    console.log(response);
  })
  .catch(function (response) {
    //handle error
    console.log(response);
  });