PC端导出xlsx文件列表

  1. 下载并引入
import FileSaver from 'file-saver'
import xlsx from 'xlsx'
  1. 使用Element的table表格下载
        queryDetails(obj) {
            this.alllod = this.$loading({  // 全屏loading
                lock: true,
                text: '数据较多,请耐心等待!',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            this.loading = true
            queryxfyh({
                pageNum: '',
                pageSize: '',
                dc: '2',
                ...obj
            }).then(res => {
                if (res.returnCode == 1) {
                    this.loading = false
                    this.tableData1 = res.returnData
                } else {
                    this.loading = false
                    this.$message({
                        type: "error",
                        center: true,
                        message: res.returnMsg,
                    });
                }
            }).then(() => {
                this.loading = false
                this.getHttpList()
            })
        },
        getHttpList() {
            let xlsxParam = { raw: true }   // 导出内容只做解析,不转换格式,可以解决导出数字过长时的科学计算
            let et = xlsx.utils.table_to_book(document.querySelector('#mxmytable'), xlsxParam); //此处传入table的DOM节点
            let etout = xlsx.write(et, {
                bookType: 'xlsx',
                bookSST: true,
                type: 'array'
            })
            try {
                FileSaver.saveAs(new Blob([etout], {
                    type: 'application/octet-stream'
                }), '下载文件名.xlsx');   //trade-publish.xlsx 为导出的文件名
                this.dialogTableVisible = false
                this.alllod.close();
            } catch (e) {
                console.log(e, etout);
            }
            return etout;

        }

你可能感兴趣的:(vue.js,javascript,前端)