<el-upload action="/shcam-web/yjydInfo/import" :file-list="fileList" :multiple="false"
:show-file-list="false" accept=".xlsx,.xlsm" :on-success="uploadSuccess" :on-error="uploadError">
<el-button type="ghost" icon="h-icon-import" size="mini">导入</el-button>
</el-upload>
function importExcel(data) {
return http({
method: 'post',
url: '/shcam-web/yjydInfo/import',
data,
timeout: 5 * 60 * 1000
})
}
<el-upload :file-list="fileList" :multiple="false" :http-request="httpRequest" :show-file-list="false"
accept=".xlsx,.xlsm">
<el-button type="ghost" icon="h-icon-import" size="mini">导入</el-button>
</el-upload>
httpRequest(file) {
console.log(file)
const formData = new FormData()
formData.append('file', file.file)
importExcel(formData).then(res => {
this.$message.success('导入成功')
this.getTableData()
}).catch((err) => {
console.log(err)
const { response: { data: { msg } } } = err
this.$message.error(msg || '导入失败!')
})
},