亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用vue實(shí)現(xiàn)pdf預(yù)覽功能的方法

 更新時(shí)間:2023年08月09日 09:49:42   作者:weixin_49203377  
許多朋友想要材料上傳之后點(diǎn)擊預(yù)覽實(shí)現(xiàn)在瀏覽器上預(yù)覽的效果,所以本文將給大家介紹如何使用vue實(shí)現(xiàn)pdf預(yù)覽功能,文中有實(shí)現(xiàn)代碼,有需要的朋友可以參考閱讀下

背景:材料上傳之后點(diǎn)擊預(yù)覽實(shí)現(xiàn)在瀏覽器上預(yù)覽的效果

效果如下:

實(shí)現(xiàn)代碼如下://預(yù)覽和下載操作

<el-table-column fixed="right" label="操作" width="210">
              <template #default="scope">
                <span
                  @click="handleRowClick(scope.row)"
                  class="table-btn btn-handle"
                  ><i class="ri-eye-line"></i>預(yù)覽</span
                >
                <span
                  @click="handleDownLoadClick(scope.row)"
                  class="table-btn btn-handle"
                  ><i class="ri-download-2-line"></i>下載</span
                >
              </template>
            </el-table-column>
// 材料預(yù)覽
export function materialPreview(data) {
    return Http.request({
      url: '/file/preview',
      method: 'get',
      responseType: 'blob',
      data: data
    });
  }
  //預(yù)覽彈窗
  <el-dialog
      title="預(yù)覽"
      :visible.sync="PreviewDialogVisible"
      append-to-body
      width="70%"
      center
    >
      <div>
        <iframe :src="pdfSrc" width="100%" height="800px"></iframe>
      </div>
    </el-dialog>
    //data中定義的變量
      data() {
    return {
      pdfSrc: "",
      downloadUrl: "http://10.110.96.76/",
      PreviewDialogVisible: false,
      }
     }
    //預(yù)覽代碼
        handleRowClick(row) {
      materialPreview({
        fileName:row.fileName,
        realFileName:row.fileName,
      }).then((res) => {
        console.log(res);
        const blob = new Blob([res.data], { type: "application/pdf" });
        this.pdfSrc = window.URL.createObjectURL(blob);
        this.$nextTick(() => {
          this.PreviewDialogVisible = true;
        });
        console.log(this.pdfSrc);
        //window.open(this.pdfSrc) //新窗口打開,借用瀏覽器去打印
      });
    }
    //下載代碼
      handleDownLoadClick(data) {
      if (data.downloadUrl != null) {
        window.open(this.downloadUrl + data.downloadUrl);
      }
    },

后臺(tái)返回的流文件格式

到此這篇關(guān)于vue實(shí)現(xiàn)pdf預(yù)覽功能的方法的文章就介紹到這了,更多相關(guān)vue實(shí)現(xiàn)pdf預(yù)覽內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論