vue 实现excel导出功能

<el-button size="small" type="primary" @click="excel" :disabled="loading">报表导出</el-button>
async excel() {
            let apis = [{ url: 'getDetailExcel', name: '生产明细表' }, { url: 'getNodeExcel', name: '生产节点表' }, { url: 'getTotalExcel', name: '生产明细合计表' }]
            let params = {}
            for (var key in this.listQuery) {
                if (this.listQuery.hasOwnProperty(key)) {
                    var el = this.listQuery[key];
                    if (el) {
                        params[key] = el
                    }
                }
            }
            this.loading = true;
            let res = await this.$http({
                method: "get",
                url: `${this.$api}/production/${apis[this.activeName - 0].url}`,
                responseType: 'blob',
                params: params
            })
            this.loading = false;
            if (!res) {
                this.$message.warning("服务器异常");
            }
            let url = window.URL.createObjectURL(res.data)
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', apis[this.activeName - 0].name + '.xlsx')
            document.body.appendChild(link)
            link.click()
        }

 

posted @ 2018-11-09 11:00  _Gj  阅读(2510)  评论(0编辑  收藏  举报