vue-element-admin项目实现excel表格导出

vue-element-admin项目实现excel表格导出_第1张图片

  1. 安装依赖
npm install xlsx file-saver -S
npm install script-loader -S -D
  1. 在需要导出excel的页面执行以下方法
 导出xlsx文件
    exportExcel(){

      this.downloadLoading = true  


        const filterVal = ['time', 'avolt', 'bvolt', 'cvolt']

         const list = [
           {time:'1',avolt:'220',bvolt:'220',cvolt:'220'},
           {time:'2',avolt:'220',bvolt:'220',cvolt:'220'},
           {time:'3',avolt:'220',bvolt:'220',cvolt:'220'},
         ]

        const data = this.formatJson(filterVal, list)      

       import('@/vendor/Export2Excel').then(excel => {
        excel.export_json_to_excel({
          header: this.excelHear, //表头 必填
          data, //具体数据 必填
          filename: this.label, //非必填
          autoWidth: true, //非必填
          bookType: 'xlsx' //非必填
        })

        
      })
      
      this.downloadLoading = false

    },

你可能感兴趣的:(vue,总结,PC,excel,vue,element,导出)