在vue中使用axios發送post請求,參數方式


 由於后台接收的參數格式為FormData格式

在axios中參數格式默認為

在傳參數前,將原先官方提供的格式

改為如下:

axios({
  url: '../../../room/listRoomPage',
  method: 'post',
  data: {offset: 0, limit: 9999, roomCode: "", roomtypeId: 0, floorId: 0},
  transformRequest: [function (data) {
    var oMyForm = new FormData();
    oMyForm.append("offset", 0);
    oMyForm.append("limit", 9999);
    oMyForm.append("roomCode", "");
    oMyForm.append("roomtypeId", 0);
    oMyForm.append("floorId", 0);
    console.info(oMyForm);
    return oMyForm;
  }],
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

成功得到后台返回的數據

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM