<template>
  <div class="container">
    <pdf v-for="(item, index) in pdfNumPages" :key="index" :src="pdfUrl" :page="index + 1" />
  </div>
</template>

<script>
import pdf from "vue-pdf";
export default {
  name: "PolicyVirtualDetail",
  components: {
    pdf
  },
  data() {
    return {
      url: "",
      pdfUrl: "",
      pdfNumPages: null
    };
  },
  mounted() {
    this.setDetail();
  },
  methods: {
    setDetail() {
      const { url } = this.$route.query;
      if (!url) this.$router.back();
      this.url = url;
      this.pdfTask();
    },
    pdfTask() {
      this.pdfUrl = pdf.createLoadingTask(this.url);
      this.pdfUrl.promise
        .then(pdf => {
          this.pdfNumPages = pdf.numPages;
        })
        .catch(err => {
          console.error(err);
        });
    }
  }
};
</script>
<style lang="less" scoped></style>
