1. 安装相关依赖
主要是两个依赖
npm install --save xlsx file-saver
2.组件里头引入
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
3.调用
exportExcel () {
var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'))
var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), 'sheetjs.xlsx')
return wbout
},