使用第三方插件vue-json-excel实现vue的Excel导出功能

第三方插件选择——vue-json-excel

  1. 安装vue-json-excel
npm install vue-json-excel
# or
cnpm install vue-json-excel//速度更加快

2.作为组件导入vue
一般在main.js中导入注册进行全局使用

// vue-json-excel插件来实现简单Excel表格的导出功能
import JsonExcel from 'vue-json-excel'
 // 将Excel导出器作为vue实例的组件
Vue.component('downloadExcel', JsonExcel)
  1. 使用
     <download-excel
            :data="voteDataList"
            :fields="json_fields"
            name="投票数据统计列表"
            class="output-excel">
            导出数据</download-excel >
//data:数据源
//name:导出Excel文件名
//fields:Excel中表头的名称
      json_fields: {
        序号: 'serialId',
        标题: 'voteTitle',
        发布时间: 'publishDate'
      }
image.png

image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容