admin管理员组

文章数量:1583366

vue下载音频

这里是将音频流使用xml请求转化成blob格式,然后使用a链接方法进行下载;话不多说,直接上代码;

    //下载
    handleDownload(row){
      this.$message({
          message: '文件正在下载,请您耐心等待!',
          type: 'warning'
        });
      let path = row.filePath;// 后端返的地址例如https://xzyp/xxx.mp3
      const xhr = new XMLHttpRequest();
      xhr.open('get',path);
      xhr.responseType='blob';
      xhr.send()
      xhr.progress=function(){
        console.log(this);
      }
      xhr.onload= function(){
        if(this.status===200||this.status === 304){
          const url =URL.createObjectURL(this.response);
          let a = document.createElement("a");
          a.href = url;
          a.download = row.title;
          document.body.appendChild(a)
          a.click();
          document.body.removeChild(a)
        }
      }
    }

本文标签: 音频vue