码迷,mamicode.com
首页 > 其他好文 > 详细

vue实现前端导出excel表格

时间:2018-08-01 16:01:24      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:nload   lob   src   file   stat   解析   format   data   vendor   

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 }

 

vue实现前端导出excel表格

标签:nload   lob   src   file   stat   解析   format   data   vendor   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!