pdfvuer icon indicating copy to clipboard operation
pdfvuer copied to clipboard

[Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'pdfdata')"

Open Rombond opened this issue 2 years ago • 0 comments

On vue 2 with pdfvuer, i got an error only if i use a v-for don't know why. Error : [Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'pdfdata')" Source code :

<template>
  <pdf :src="this.pdfdata" v-for="i in this.pdfnum" :key="i" :page="i">
    <template slot="loading">loading....</template>
  </pdf>
</template>

<script>
import PdfvuerVue from 'pdfvuer';

export default {
  components: {
        pdf: PdfvuerVue,
    },

    data: () => ({
        pdfnum: 0,
        pdfdata: null,
    }),

    mounted() {
        this.pdfdata = PdfvuerVue.createLoadingTask('./myPDF.pdf')
        this.pdfdata.then(pdf => {
            this.pdfnum = pdf.numPages;
        })
    },
</scritp>
<style>
</style>

If i change the template to this, it works perfectly :

<template>
  <pdf :src="this.pdfdata" :page="1">
    <template slot="loading">loading....</template>
  </pdf>
  <pdf :src="this.pdfdata" :page="2">
    <template slot="loading">loading....</template>
  </pdf>
</template>

I tried to put the v-for in a <div> but i doesn't change anything.

Rombond avatar Nov 28 '21 22:11 Rombond