方案1
1安装插件
npm install vue-json-excel
2在min.js中导入
import JsonExcel from 'vue-json-excel'
Vue.component('downloadExcel', JsonExcel)
3 代码实现
<download-excel
class = "export-excel-wrapper"
:data = "json_data"
:fields = "json_fields"
name = "远程诊断报告导出.xls">
<!-- 上面可以自定义自己的样式,还可以引用其他组件button -->
<el-button type="primary" size="small">导出EXCEL</el-button>
</download-excel>
data() {
return {
json_fields: {
"头部-诊断名称": "name", //常规字段
"头部-联系电话": "phone.mobile", //支持嵌套属性
"头部-损坏区域代码": {
field: "phone.landline",
//自定义回调函数
callback: value => {
return `损坏区域代码 - ${value}`;
}
}
},
json_data: [
{
name: "损坏的组件一",
city: "New York",
country: "United States",
birthdate: "1978-03-15",
phone: {
mobile: "1-541-754-3010",
landline: "(541) 754-3010"
}
},
{
name: "损坏的组件二",
city: "Athens",
country: "Greece",
birthdate: "1987-11-23",
phone: {
mobile: "+1 855 275 5071",
landline: "(2741) 2621-244"
}
}
],
json_meta: [
[
{
" key ": " charset ",
" value ": " utf- 8 "
}
]
]
};
}

方案2
1安装三个插件
npm install file-saver
npm install xlsx
npm install script-loader
2在共享文件夹中assets创建存放Blob和Export2Excel两个js文件的文件夹以及文件
Blob
/* eslint-disable */
/* Blob.js*/
/*global self, unescape */
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
plusplus: true */
/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
(function (view) {
"use strict";
view.URL = view.URL || view.webkitURL;
if (view.Blob && view.URL) {
try {
new Blob;
return;
} catch (e) {
}
}
// Internally we use a BlobBuilder implementation to base Blob off of
// in order to support older browsers that only have BlobBuilder
var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function (view) {
var
get_class = function (object) {
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1