vue3 excel下载 xlsx插件
1.安装插件:
npm install --save xlsx file-saver
2.页面中引入
-
// 引入file插件
-
import FileSaver from "file-saver";
-
// 引入xlsx插件
-
import * as XLSX from "xlsx";3.事件
const export = () => {
//导出当前表格
var wb = XLSX.utils.table_to_book(document.querySelector("#tableId")); //表格id
var wbout = XLSX.write(wb, {
bookType: "xlsx",
bookSST: true,
type: "array",
});
try {
FileSaver.saveAs(
new Blob([wbout], { type: "application/octet-stream" }),
"order.xlsx"
); //文件名
} catch (e) {
if (typeof console !== "undefined") console.log(e, wbout);
}
return wbout;
},