- 直接上代码
async exportData(){ const returnArr = [] for(let i=0;i<index;i++){ const data = { ... } console.log("正在合并数据") data["page_index"] = i this.exportExcel(data).then((result) => { returnArr.push.apply(returnArr,result) }) } this.$axios.all(returnArr).then(this.$axios.spread(function (...returnArr){ require.ensure([], () => { const data = this.formatJson(filterVal, returnArr) export_json_to_excel(tHeader, data, "漏洞") // 参数说明 第一个,头部信息 第二个,数据 第三个,表名 }) })) }
- 说明:
- exportData方法需要注明为async,
exportExcel
方法中返回axios对象
exportExcel (data) { this.exportStatus = true return this.$axios({ url: "http://ccops-paas.cmecloud.cn/t/phoenix/vul/list/", data: data, method: "post", responseType: "json", }).then((response) => { this.exportStatus = false var downloadlist = response.data.returnlist return downloadlist }).catch(e=>{ this.$bkMessage({theme:"error",message:"请求数据失败!"}) this.exportStatus = false }) },
- exportData方法需要注明为async,
网友评论