1.安装插件
cnpm 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}`;
}
}
},