vue实现前端导出excel表格

1.在src目录下创建一个文件(vendor)进入Blob.jsExport2Excel.js

2.npm install -S file-saver 用来生成文件的web应用程序

3.npm install -S xlsx 电子表格格式的解析器

4.npm install -D script-loader 将js挂在在全局下

5.写事件

 1  handleDownload(){
 2           import('@/vendor/Export2Excel').then(excel => {
 3             const tHeader = ['timestamp', 'title', 'type', 'importance', 'status']//
 4             const filterVal = ['timestamp', 'title', 'type', 'importance', 'status']//
 5             const data = this.formatJson(filterVal, this.list)
 6             excel.export_json_to_excel({
 7               header: tHeader,
 8               data,
 9               filename: 'table-list'
10             })
11           })
12         },

6.

1  formatJson(filterVal, jsonData) {
2           return jsonData.map(v => filterVal.map(j => {
3               return v[j]
4           }))
5         }
6 }

猜你喜欢

转载自www.cnblogs.com/yangguoe/p/9401540.html