解决a标签download无效、只能预览

2022-02-23  本文已影响0人  逸笛
  downloadFile(url, label) {
    axios
      .get(url, { responseType: "blob" })
      .then((response) => {
        const blob = new Blob([response.data]);
        const link = document.createElement("a");
        link.href = URL.createObjectURL(blob);
        link.download = label;
        link.click();
        URL.revokeObjectURL(link.href);
      })
      .catch(console.error);
  },


      this.$api.post(
        "/cdn/cdnDownload",
        {
          fid: type === 2 ? item.key : item.id,
          t: this.$utils.getCookie(this.$glb.fmCookieName),
        },
        (res) => {
          if (res.code === 200) {
            console.log(res.data.cdnUrl, "res.data.cdnUrl");
            this.$utils.downloadFile(res.data.cdnUrl, res.data.name);
          } else {
            this.$notify.warning({
              title: "提示",
              message: res.msg,
            });
          }
        },
        3
      );
上一篇 下一篇

猜你喜欢

热点阅读