<template>
  
 <el-button style="float: right; margin: 10px" type="primary" @click="export2">导出</el-button>

  

     <!-- 导出表格 start--> 
      <el-table class="tableExport" :data="tableData" hidden>
                   
需要导出哪些列,就写哪些 <el-table-column label="id" prop="id"/> <el-table-column label="名称" prop="name"/> <el-table-column label="类型" prop="type"/>
      
</el-table> <!-- 导出表格 end--> </template>

  

<script>
//"xlsx": "^0.18.5",
//"file-saver": "^2.0.5",

  

import FileSaver from 'file-saver'
var XLSX = require('xlsx')




 methods: {
      export2() {
        //  .table要导出的是哪一个表格
        var excelDom = XLSX.utils.table_to_book(document.querySelector('.tableExport'))
        var excelType = XLSX.write(excelDom, {
          bookType: 'xlsx',
          bookSST: true,
          type: 'array',
        })
        try {
          //  name+'.xlsx'表示导出的excel表格名字
          FileSaver.saveAs(new Blob([excelType], { type: 'application/octet-stream' }), '产品数据表格.xlsx')
        } catch (e) {
          if (typeof console !== 'undefined');
        }
        return excelType
      },

</script>

//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿//  文字少不能投稿