1.前端页面
<el-upload class="upload-demo" ref="upload" :limit="3" :auto-upload="false" :on-change="handleChange" :on-remove="handleRemove" :file-list="fileList" action="" name="paramfile"> <el-button size="small" type="primary">选取文件</el-button> </el-upload>
2.js部分
一定要加这两个方法,之前没有加,以为会自动赋值filelist
handleChange(file, fileList) { this.files.push(file.raw); }, handleRemove(file, fileList) { this.files = this.files.filter(t => { return t != file.raw }); },
方法提交部分
var formData = new FormData(); $this.files.forEach(item => { formData.append("paramfile",item); }); axios({ method: 'post', url: "/Device/SaveVersion", // headers里面设置token headers: { 'Content-Type': 'multipart/form-data', // "token":window.sessionStorage.getItem('token') }, data: formData,})
3.后端部分,提交后便可接收到数据