- 安装:npm install vue-json-excel
- 注册:
import Vue from "vue";
import JsonExcel from "vue-json-excel";
Vue.component("downloadExcel", JsonExcel);
- 使用:
<download-excel :data="json_data">
Download Data
<img src="download_icon.png" />
</download-excel>
- 示例:
<download-excel
class="export-excel-wrapper"
:data="json_data"
:fields="json_fields"
header="excel的头部"
name="表格名称.xls"
>
<!-- 自定义 -->
<el-button type="primary" size="small">导出</el-button>
</download-excel>
json_fields: {
序号: 'index',
姓名: 'name',
手机号: 'phone',
填充银行卡号: 'bankCard'
},
json_data: [
{
index: 1,
name: '张三',
phone: '15645689652'
},
{
index: 2,
name: '李四',
phone: '15645689652'
}
]
来源:https://github.com/jecovier/vue-json-excel#props-list