Vue project document flow display, download as a table

Vue project document flow display, download as a table

QR code display

First, let’s take a look at the document flow style. The
insert image description here
background return value is a picture, but the front-end img needs a url address, so we need to convert it into a url

  <img :src="QRcodeUrl " alt="">
        // 获取二维码
        getQRcode() {
    
    
          this.$ajax({
    
    
            method: 'post',
            url: '/getQRcode',
            data: {
    
    
              id: this.id,
              width: '200',
              height: '200',
          },
            responseType: 'blob',   //  重点
          }).then(res => {
    
    
          //  res.data是返回的文档流
            const blob = new Blob([res.data]);
            const url = window.URL.createObjectURL(blob);
            this.QRcodeUrl = url;
          })
        },

Docstream Download as Form

First, take a look at the document flow style you brought over.
insert image description here
The download method is as follows:

 //下载方法
 //blob(后台返回的文档流);fileName(文件名称,注:添加后缀名)
      downloadFile(blob, fileName) {
    
    
        if (navigator.msSaveBlob) {
    
    
          navigator.msSaveBlob(blob, fileName);
        } else {
    
    
          let url = window.URL.createObjectURL(new Blob([blob]));
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          link.setAttribute("download", fileName);
          document.body.appendChild(link);
          link.click();
          link.remove();
        }
      },
// 使用:this.downloadFile(blob, '下载文件.xlsx');

Guess you like

Origin blog.csdn.net/DevelopmentW/article/details/105836638