1. 在 src 目录下创建一个文件 (vendor) 进入 Blob.js 和 Export2Excel.js
2.npm install -S file-saver
用来生成文件的 web 应用程序
3.npm install -S xlsx
电子表格格式的解析器
4.npm install -D script-loader
将 js 挂在在全局下
5. 写事件
- handleDownload(){
- import('@/vendor/Export2Excel').then(excel => {
- const tHeader = ['timestamp', 'title', 'type', 'importance', 'status']// 头
- const filterVal = ['timestamp', 'title', 'type', 'importance', 'status']// 值
- const data = this.formatJson(filterVal, this.list)
- excel.export_json_to_excel({
- header: tHeader,
- data,
- filename: 'table-list'
- })
- })
- },
- 6.
- formatJson(filterVal, jsonData) {
- return jsonData.map(v => filterVal.map(j => {
- return v[j]
- }))
- }
- }
来源: http://www.bubuko.com/infodetail-2709652.html