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