vue使用axios提交formdata格式的數據


參考:

https://www.cnblogs.com/qwert1/p/8909455.html

https://blog.csdn.net/qq_42984640/article/details/89923797

https://blog.csdn.net/qq_42394457/article/details/96769170

https://blog.csdn.net/Zxiuping/article/details/89556035

需要創建純凈的axios,使用普通封裝的axios發送dataform后,數據會為空

這里我 通過將axios 改寫為 Vue 的原型屬性,在組件中使用axios

首先在 main.js 中引入 axios

// 將 axios 改寫為 Vue 的原型屬性
import axios from 'axios'
Vue.prototype.$ajax = axios

直接在組件的 methods 中使用 $ajax 命令

          this.$ajax({
            method: "post",
            url: "/zy-api/item/medicinal/medicinalimg",
            data: imgfile
          }).then(resp => {
            if (resp.data.flag != true) {
              // 失敗
              this.$message({
                message: "上傳葯材圖片失敗",
                type: "warning"
              });
            }
          });

 


免責聲明!

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



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