1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > ElementUI在el-table基础上进行导出.xls表格操作

ElementUI在el-table基础上进行导出.xls表格操作

时间:2023-03-17 15:25:11

相关推荐

ElementUI在el-table基础上进行导出.xls表格操作

1.截图

2.导出按钮

<el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>

3.导出方法

this.downloadFile为全局挂载的方法

/** 导出按钮操作 */handleExport() {// 导出接口exportHealthSubsidy(this.ids).then((res) => {this.downloadFile(res, "文件导出.xls");})},

对应接口

4.el-table复选框操作

组件自带方法@selection-change

<el-table ref="multipleTable" v-loading="loading" :data="subsidyList" @selection-change="handleSelectionChange">

5.实现方法handleSelectionChange

// 复选框操作handleSelectionChange(selection) {this.ids = selection.map((item) => item.applyId);this.single = selection.length != 1;this.multiple = !selection.length;},

6.data中定义的参数

// 选中数组ids: [],// 非单个禁用single: true,// 非多个禁用multiple: true,

7.新建downloadFile.js文件

import { Message } from "element-ui"// 导出export function downloadFile(blob, fileName) {Message.success({message: '正在导出',type: 'success',offset: 250})if (navigator.msSaveBlob) {navigator.msSaveBlob(blob, fileName)} else {const url = window.URL.createObjectURL(new Blob([blob]))const link = document.createElement('a')link.style.display = "none"link.href = urllink.setAttribute("download", fileName)document.body.appendChild(link)link.click()URL.revokeObjectURL(link.href)document.body.removeChild(link)// Message.success({// message: '导出成功',// type: 'success',// offset: 250// })}}

8.在main.js中全局挂载

import { downloadFile } from "@/utils/downloadFile"Vue.prototype.downloadFile = downloadFile

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。