前端導(dǎo)出功能實現(xiàn)

前端導(dǎo)出,不需要調(diào)用后臺接口后臺導(dǎo)出,前端直接實現(xiàn)導(dǎo)出功能

導(dǎo)出table數(shù)據(jù)

js 引入

? import?FileSaver?from?"file-saver";

??import?XLSX?from?"xlsx";

table id??out-table

<el-table

??????id="out-table"

??????:data="tableData"

??????v-loading="loading"

??????style="width:?100%"

??????max-height="100%"

??????class="dialog-table"

??????header-row-class-name="table-header"

??????row-class-name="table-row"

????>? ? </el-table>

<el-button?class="search-btn?out-btn"?@click="leadingOut"?type="success">導(dǎo)出</el-button>

js代碼? table 的id 需要為?out-table

leadingOut()?{

??????console.log("點擊導(dǎo)出");

??????this.loading=true;

??????var?wb?=?XLSX.utils.table_to_book(document.querySelector("#out-table"),{raw:true});

??????var?wbout?=?XLSX.write(wb,?{

????????bookType:?"xlsx",

????????bookSST:?true,

????????type:?"array"

??????});

??????try?{

????????FileSaver.saveAs(

??????????new?Blob([wbout],?{?type:?"application/octet-stream"?}),

??????????`${this.title}.xlsx`

????????);

?????????this.loading=false;

??????}?catch?(e)?{

????????if?(typeof?console?!==?"undefined")?console.log(e,?wbout);

??????????this.loading=false;

??????}

??????return?wbout;

????},

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容