npm install vue-json-excel -S
接着在main.js中引入
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
在要用的页面
<download-excel id="export" class="export-excel-wrapper" :data="msgList" :fields="json_fields" :header="title" name="保护记录.xls">
<span>导出</span>
</download-excel>
其中:data就是要绑定的数据源, :header是excel内容的标题,name是excel文件的名称。json_fields是要导出的数据对应关系
json_fields = {
'时间': 'time',
'名称': 'name',
'信息': 'info'
}
注意 json_fields中的字段要与绑定的data一致!