- 主要是两个依赖:(xlsx 和 file-saver)
npm install --save xlsx file-saver
https://github.com/SheetJS/js-xlsx](https://github.com/SheetJS/js-xlsx)
https://github.com/eligrey/FileSaver.js](https://github.com/eligrey/FileSaver.js
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
exportExcel () {
/* generate workbook object from table */
let wb = XLSX.utils.table_to_book(document.querySelector('#rebateSetTable')); //表格的id名
/* get binary string as output */
let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
try {
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '用户提交返利表.xlsx');
} catch (e)
{
if (typeof console !== 'undefined')
console.log(e, wbout)
}
return wbout
},
<div class="export">
<el-button @click="exportExcel" style="margin-top: 2px;" size="medium" type="success">导出</el-button>
</div>