美文网首页
解决a标签download无效、只能预览

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

作者: 逸笛 | 来源:发表于2022-02-23 15:04 被阅读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
      );

相关文章

网友评论

      本文标题:解决a标签download无效、只能预览

      本文链接:https://www.haomeiwen.com/subject/ntvolrtx.html