<el-upload
ref="upload"
:limit="1"
:http-request="handleImport"
action=""
:auto-upload="true"
:show-file-list="false"
class="upload-button"
accept=".xls,.xlsx">
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-upload2"
size="mini"
>导入</el-button>
</el-col>
</el-upload>
handleImport(file) {
const _file = file.file
const isLt10M = _file.size / 1024 / 1024 < 10
// 通过 FormData 对象上传文件
var formData = new FormData()
formData.append('file', _file)
if (!isLt10M) {
this.$message.error('请上传10M以下的.xlsx文件')
return
}
this.$refs['upload'].clearFiles()
// 发起请求
workloadUpload(formData).then(res => {
this.$refs.upload.clearFiles()
if (res.code === 200) {
// 成功
this.getList()
} else {
this.$message({
type: 'warning',
message: res.msg
})
}
}).catch(e => {})
},