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
})
}