导出功能
第一步:
<script>里引入
import FileSaver from "file-saver";
import XLSX from "xlsx";
第二步:
a-table(要导出的表格)标签加id:id="daochu"
第三步:
导出按钮上加点击事件, @click="daochu"
第四步:
methods里写:
//excel导出功能
daochu() {
/* generate workbook object from table */
var wb = XLSX.utils.table_to_book(document.querySelector("#daochu"));
/* get binary string as output */
var 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;
},