在表格导出的时候出现这个错误,是因为把id获取错误
因为封装的方法里有id,但是页面上面没有找到,所以报错
/**
* 导出
* @param mainTitle 主标题
* @param subTitle 副标题
* @param reqData
* @returns {any}
*/
exportTable(mainTitle,subTitle,reqData){
/* generate workbook object from table */
var timeTitle ='';
console.log('reqData:',reqData)
if(reqData.beginTime&&reqData.endTime){
timeTitle = "-"+reqData.beginTime+"-"+reqData.endTime;
}
if(subTitle){
subTitle='-'+subTitle
}else{
subTitle = '';
}
let sheetjs=mainTitle+subTitle+timeTitle;
let xlsxParam = { raw: true }
var wb = XLSX.utils.table_to_book(document.querySelector('#outTable'),xlsxParam)
/* 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' }), sheetjs+".xlsx")
} catch (e) { if (typeof console !== 'undefined') console.log(e, wbout) }
return wbout
},
给表格添加上id就好了
<el-table
:data="reportData" stripe border style="width:100%;" :height="tableHeight" highlight-current-row
:header-cell-style="headerCellStyle" id='outTable' class="tableStyle" v-loading="loading">
<el-table-column
type="index"
label="序号"
align="center"
width="50"
>
</el-table-column>
</el-table>
使用导出方法:
exportExcel () {
comon.exportTable('xxx表','',this.reqData)
}