我這里為了同學們好理解,把所有元素都寫到一個頁面。
1.第一步安裝插件
-
-
2.第二步在mian.js中設置全局
-
-
import FileSaver from 'file-saver'
-
-
-
Vue.prototype.$FileSaver = FileSaver;
-
Vue.prototype.$XLSX = XLSX;
3.第三步使用
-
-
-
<el-button @click="o" type="success" round>導出</el-button>
-
-
-
-
-
:default-sort="{ prop: 'date', order: 'descending' }"
-
-
<el-table-column prop="date" label="日期" sortable width="180">
-
-
<el-table-column prop="name" label="姓名" sortable width="180">
-
-
<el-table-column prop="address" label="地址" :formatter="formatter">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
address: "上海市普陀區金沙江路 1518 弄",
-
-
-
-
-
address: "上海市普陀區金沙江路 1517 弄",
-
-
-
-
-
-
-
let tables = document.getElementById("ou");
-
let table_book = this.$XLSX.utils.table_to_book(tables);
-
var table_write = this.$XLSX.write(table_book, {
-
-
-
-
-
-
-
new Blob([table_write], { type: "application/octet-stream" }),
-
-
-
-
if (typeof console !== "undefined") console.log(e, table_write);
-
-
-
-
-
-
可以看到已經導出
實際工作中導出按鈕單獨抽離出去做到可以復用才是比較合理的