vue实现前端导出excel表格

时间:2018-08-01 15:52:17   收藏:0   阅读:1234

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 }

 

原文:https://www.cnblogs.com/yangguoe/p/9401540.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!