本项目要求:用户下载excel模板,填写资料后上传
模板保存在项目文件中,使用a标签点击下载
html
html
<el-upload
v-model:file-list="fileList"
:before-upload="beforeUpload"
:limit="1"
:on-exceed="handleExceed"
:show-file-list="false"
>
<el-button size="small" type="primary">
<vab-icon icon="file-excel-2-line" />
导入EXCEL
</el-button>
</el-upload>
<el-button size="small" type="primary">
<vab-icon icon="download-2-line" />
<a
download="收款导入模板"
href="./static/collection.xls"
style="color: #ffffff"
>
下载模板
</a>
</el-button>
上传功能:
javascript
export function importExcelDetail(file) {
return request({
url: '/api/v1/pri/cost-master/import-excel-detail',
method: 'post',
data: {
files: [file],
},
})
}
javascript
const beforeUpload = (file) => {
importExcelDetail(file).then((res) => {
if (res.code === 200) {
$baseMessage('导入成功!', 'success')
fetchData()
}
})
}
const handleExceed = () => {
ElMessage.warning('只能选择一个文件')
}