vue 文件导出功能

带token形式的导出


接口的js:
// 采购管理-订货通知 export function orderInform (orderId,userId) { return `${window.g_api.BASE_API}/order-item-pricing/inform?orderId=${orderId}&userId=${userId}` } 页面代码: window.open( orderInform( this.orderInformationDisplayStorage[0].id, window.localStorage.getItem("userIds") ), "_self", "width=0,height=0" );

 

不带token:

let params = {
        endDate: this.searchParams.endDate,
        startDate: this.searchParams.startDate,
        searchStr: this.searchParams.searchStr,
      };
this.$confirm("是否导出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        window.open(`/hero-log/error/exportLogError?${this.website.tokenHeader}=${getToken()}&endDate=${params.endDate}&startDate=${params.startDate}&searchStr=${params.searchStr}`,'_self', 'width=0,height=0');
      });
走正常请求的导出:


api:
  /* 库存总览导出模板 */
  stockExport() {
    return request({
      url: "/stock/export",
      method: "get",
    }).then((res) => {
      return this.backErr(res);
    });
  },

html:
stockExport() {
      inventory.stockExport().then((res) => {
        window.open(res.data, "_self", "width=0,height=0");
      });
    },

最后一种方式,根据自己需求实现导出

res.data.data.forEach((element) => {
              const iframe = document.createElement("iframe");
              iframe.src = element;
              iframe.style.display = "none";
              document.body.appendChild(iframe);
              this.$emit("confirmExportSuccess");
            });

 

posted @ 2021-07-21 16:57  遇你温柔如初  阅读(2110)  评论(0编辑  收藏  举报