1、安装vue-json-excel
npm install vue-json-excel -S
2、main.js文件中引入
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
3、使用
<template>
<download-excel
class="export-excel-wrapper"
:data="DetailsForm"
:fields="json_fields"
:header="title"
name="需要导出的表格名字.xls"
>
<el-button type="success">导出</el-button>
</download-excel>
</template>
4、相关数据
-
DetailsForm:需要导出的数据
-
title:表格标题
-
json_fields:里面的属性是excel表每一列的title,用多个词组组成的属性名(中间有空格的)要加双引号; 指定接口的json内某些数据下载,若不指定,默认导出全部数据中心全部字段
//这里注意名称字段需要加单引号 json_fields:{ "工位区": 'area', "工位数": 'areaNumber', "使用部门": 'department', "实际划分工位数": 'departmentNumber', "使用工位数": 'staffNumber', "设备占用": 'equipmentNumber', "空置工位数": 'leisureNumber', }