vue实现按钮下载功能

2020-01-02  本文已影响0人  zhu733756

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);

        });

    }

上一篇 下一篇

猜你喜欢

热点阅读