美文网首页
vue实现按钮下载功能

vue实现按钮下载功能

作者: zhu733756 | 来源:发表于2020-01-02 12:31 被阅读0次

onDownload() {

      this.$http

        .get(

          "your-url",

          {

            responseType: "blob" ,//重要

          }

        )

        .then(response => {

          if (response.message) {

            this.$message.error(response.message);

            return;

          }

          let blob = new Blob([response.data], { type: "application/zip" });

          let link = document.createElement("a");

          let url = window.URL.createObjectURL(blob)

          link.href = url;

          link.download = this.projectName;

          link.click();

          URL.revokeObjectURL(url); //释放内存

        })

        .catch((e) => {

          this.$message.error(this.$store.getters.$lang.messages.errorLoad+":"+e);

        });

    }

相关文章

网友评论

      本文标题:vue实现按钮下载功能

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