axios 配置
axios({
headers: {
'Content-Type': 'multipart/form-data',
},
});
element ui 配置
<el-upload :on-change="handleFilesChange"></el-upload>
handleFilesChange (file) {
// 通过 raw 属性获取文件对象
const file = file.raw
}
上传多个文件构成的数组
const formData = new FormData();
files.map((item) => {
// `file[]` 中的 file 表示字段名
formData.append('file[]', item);
});