1.template中
<el-button size="small" type="primary" icon="plus" @click="handleExcelExport('ExcelExport.xlsx')">导出</el-button>
2.js方法
// 导出
const handleExcelExport = async()=>{
// if (!fileName || typeof fileName !== 'string') {
// fileName = 'ExcelExport.xlsx'
// }
// exportExcel(tableData.value, fileName)
let res = await exportExcel({
companyId:searchInfo.value.companyId,
month:searchInfo.value.month,
page:1,
pageSize:9999
})
const blob = new Blob([res],{type: "application/vnd.ms-excel;charset=utf-8"})
const fileName = '员工考勤信息.xlsx'
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a')
link.href = url;
link.setAttribute('download',fileName)
document.body.appendChild(link);
link.click();
if(res.code===7){
ElMessage({
type:'error',
message:res.msg
})
}
console.log('导出',res)
}