一、element-ui 
1安装依赖
Element组件库中的el-table表格导出需要的主要是两个依赖:(xlsx 和 file-saver)
npm install --save xlsx file-saver
2、页面
<el-tooltip content="导出数据" placement="top">
<el-button type="warning" plain @click="exportExcel()">导出</el-button>
</el-button>
</el-tooltip>
<el-table
v-loading="loading"
element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(0, 0, 0, 0.8)"
:data="dataList"
class="table"
id="out-table"
:header-cell-style="{background:&quot;rgb(48, 65, 86)&quot;,color:&quot;white&quot;}"
border
>
<el-table-column type="index" />
<el-table-column prop="param" label="参数" />
<el-table-column prop="paramType" label="参数值类型" />
<el-table-column prop="example" label="示例" /><el-table>

3、js

import FileSaver from 'file-saver'
import XLSX from 'xlsx'

loading: true,
dataList: [{
param: 'phone',
paramDesc: '需要发送的手机号码',
example: 'null'
}, {
param: 'templateId',
paramDesc: '模板id,联系客服人员申请成功的模板ID',
example: 'null'
}, {
param: 'variable',
paramDesc: '',
example: 'null'
}],
    exportExcel() {
// 定义导出Excel表格事件
/* 从表生成工作簿对象 */
var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'))
/* 获取二进制字符串作为输出 */
var wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: true,
type: 'array'
})
try {
FileSaver.saveAs(
// Blob 对象表示一个不可变、原始数据的类文件对象。
// Blob 表示的不一定是JavaScript原生格式的数据。
// File 接口基于Blob,继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
// 返回一个新创建的 Blob 对象,其内容由参数中给定的数组串联组成。
new Blob([wbout], { type: 'application/octet-stream' }),
// 设置导出文件名称 xxx.xlsx
'xxx.xlsx'
)
} catch (e) {
if (typeof console !== 'undefined') console.log(e, wbout)
}
return wbout
}
2、效果
 

 

二、ivew 可参考官方接口(https://iviewui.com/docs/guide/install
<Button style="width: 95px" type="success" icon="ios-download-outline" @click="exportData()">导出</Button>
<Table
:columns="tableColumn"
:data="tableData"
stripe border
ref="table"
:height="tableHeight"
></Table>
   tableHeight: 400px,
tableColumn:[
{
type: "index",
align: 'center',
width: 60,
fixed: 'left'
},
{
type: "phone",
align: 'center',
width: 60,
fixed: 'left'
},
]
tableData:[
{
param: 'phone',
paramDesc: '需要发送的手机号码',
example: 'null'
}, {
param: 'templateId',
paramDesc: '模板id,联系客服人员申请成功的模板ID',
example: 'null'
}, {
param: 'variable',
paramDesc: '',
example: 'null'
}
],

 exportData() {
this.$refs.table.exportCsv({
filename: '语音信息',
});
}


最新文章

  1. hdu 1241 Oil Deposits
  2. Linux命令工具 top详解
  3. POJ - 2965 - The Pilots Brothers&amp;#39; refrigerator (高效贪心!!)
  4. apache设置映射文件夹的配置方法
  5. MongoDB再实测
  6. Backdoor CTF 2013: 电子取证 250
  7. C++标准库之vector(各函数及其使用全)
  8. asp.net core 教程(四)-项目结构
  9. VS2010 常见错误类型汇总
  10. vue 使用小结 2019.03
  11. docker简单介绍----镜像和容器管理
  12. socket.io的websocket示例
  13. iOS 如何优化项目
  14. 在linux上创建slave节点
  15. 利用SimpleDateFormat进行时间的跨时区转换 - Java
  16. Alpha 冲刺 —— 十分之九
  17. Nginx模块Lua-Nginx-Module学习笔记(一)Nginx Lua API 接口详解
  18. bootstrap使用记录
  19. Hive中创建结构体、数组以及map
  20. javascript中对象和数组的异同点

热门文章

  1. linux之nfs
  2. K8S部署遇到的问题处理汇总
  3. C++静态成员函数小结
  4. PAT基础编程练习
  5. 90万条数据玩转RFM用户分析模型
  6. Codeforces_831
  7. ARTS Week 7
  8. redis命令总结与持久化
  9. JDK14都要问世了,你还在用JDK8吗
  10. 多版本python创建虚拟环境