一、安装vue-json-excel
npm install vue-json-excel -S
二、main.js中引入
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
三、使用(html部分)
<template>
<download-excel
class="excel"
:data="tabDataList"
:fields="json_data"
:header="title"
name="需要导出的表格名字.xls"
>
<!-- 上面可以自定义自己的样式,还可以引用其他组件button -->
<el-button type="success">导出</el-button>
</download-excel>
</template>
(js部分)
<script>
title: "操作日志表格", //表格标题
//j键名是excel表每一列的title
json_data: {
时间: "time",
操作: "event",
.......
},
tabDataList:[], //需要导出的数据
</script>