最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

可在手机浏览器下载文件的方法

常识 admin 34浏览 0评论

可在手机浏览器下载文件的方法

后端获取的数据为blob格式的,结合a标签。

axios({

        method: "get",

        url: "/api/xxxx",

        params: { xxxx },

        responseType: "blob"

      }).then(res => {

        if (window.navigator.msSaveOrOpenBlob) {

          navigator.msSaveBlob(res.data, this.title);

        } else {

          const elink = document.createElement("a");

          elink.download = this.title;

          elink.style.display = "none";

          elink.href = URL.createObjectURL(res.data);

          document.body.appendChild(elink);

          elink.click();

          document.body.removeChild(elink);

        }

      });

可在手机浏览器下载文件的方法

后端获取的数据为blob格式的,结合a标签。

axios({

        method: "get",

        url: "/api/xxxx",

        params: { xxxx },

        responseType: "blob"

      }).then(res => {

        if (window.navigator.msSaveOrOpenBlob) {

          navigator.msSaveBlob(res.data, this.title);

        } else {

          const elink = document.createElement("a");

          elink.download = this.title;

          elink.style.display = "none";

          elink.href = URL.createObjectURL(res.data);

          document.body.appendChild(elink);

          elink.click();

          document.body.removeChild(elink);

        }

      });

发布评论

评论列表 (0)

  1. 暂无评论