Element+Axios上传图片 OR 文件

Vue template

<el-upload
    class="avatar-uploader"
    action
    name="file"
    :show-file-list="false"
    :http-request="upLoad" 
    > 
        <div class="upload-btn">上传</div> 
</el-upload>

Vue Methods

upLoad(fileObj) {
      uploadImg(fileObj)  // 这里是Axios请求方法
    },  

Axios请求

import request from '@/utils/request' // 实例化 Axios

export function uploadImg(fileObj,modular="") {
    let formData = new FormData();
    formData.set("file", fileObj.file);
    formData.set("modular", modular);
    return request({
      url: '/common/uploadImage',
      headers: {
        "Content-type": "multipart/form-data"
      },
      method: 'post',
      data: formData
    })
}

Element+Axios上传图片 OR 文件

上一篇:安卓基础(页面导航传递数据)


下一篇:Microsoft .NET Pet Shop 4: Migrating an ASP.NET 1.1 Application to 2.0