实现pdf预览

93 阅读1分钟
<iframe :src="pdfUrl" frameborder="0" style="width: 100%; height: 78vh"></iframe>
async getData() {
      try {
        const auth = await AuthService.getUser();
        const token = auth.access_token;
        const res = await axios({
          url: `${webConfig.dmapi.url}/hud/document/${this.$route.params.documentId}`,
          headers: {
            authorization: `Bearer ${token}`,
            'Content-Type': 'application/vnd.ms-excel;charset=utf-8',
            Accept: '*/*'
          },
          responseType: 'arraybuffer'
        });
        if (res?.data) {
          const blob = new Blob([res.data], {
            type: 'application/pdf'
          });
          // console.log('bolb---', blob)
          this.pdfUrl = window.URL.createObjectURL(blob);
        }
      } catch (err) {
        console.log('err---', err);
      }
    },