el-upload组件调用后端接口上传文件实践

要点说明:

  • 使用:http-request覆盖默认的上传行为,可以添加除文件外的其他参数,注意此时仍需保留action属性,action可以传个空串

  • 给http-request属性绑定的函数,函数入参必须为param

  • 调用接口请求,注意 headers:{

    'content-type':'multipart/form-data'

    }时,请求参数需要通过new FormData()方式传入

  • 获取上传接口返回值:this.uploadFileUrl2 = res.data.data



    图片1(点击上传)

    data() {
    return {

    复制代码
              fileList: [],
              uploadFileUrl1:''
              
          }
      },

    uploadFileHttp1(param) {
    var file = param.file
    let params = new FormData()
    params.append("upload_type", 'public');
    params.append("file", file);
    axios({
    method:'post',
    url:'https://xxxxx/upload_file',
    data:params,
    headers:{
    'content-type':'multipart/form-data'
    }
    }).then(res => {
    console.log(res)
    this.uploadFileUrl1 = res.data.data

    复制代码
              })
              .catch(err => {
                  console.log(err)
              })
          },
相关推荐
CoderYanger15 分钟前
Java EE 进阶:12.Spring AOP(第二弹)
java·前端·数据库·spring boot·spring·java-ee·mybatis
用户69371750013843 小时前
大模型蒸馏到底在蒸什么?一篇文章搞懂知识蒸馏概念
前端·后端·github
徐小夕3 小时前
实测 10 个前端 UI 生成开源 Skill|AI 输出直达上线标准
前端·vue.js·github
tong_li3 小时前
给娃做个 AI 陪写作业助手:LangChain4j 入门(八):AI 知道这字哪课学的(SQLite 结构化查询入门)
前端·langchain
bai2733 小时前
同一条 q=a+b:URLSearchParams 读成空格、decodeURIComponent 读成加号,11 条查询串打进裸 socket 的实测
javascript·后端
用户69371750013844 小时前
当 Claude 开始反对蒸馏,我想起了那 700 万份盗版书籍
前端·后端·面试
tryCbest4 小时前
Python 爬虫扩展篇(一):APP 抓包与 JS 逆向入门——从看见流量到读懂签名
javascript·爬虫·python
zhanlang02174 小时前
HTML 零基础入门到企业实战全套教程【10.1】综合实战|从零开发静态企业官网:需求分析、页面结构规划、素材准备
前端·html
软件技术NINI4 小时前
基于SpringBootVue 的出租车拼车系统
vue.js·spring boot·spring·毕业设计·毕设
Bczheng14 小时前
浏览器访问本地html和服务器html的流程
前端