How to implement vue-pdf with Vuex?

Viewed 360

I have a Vuex state where i define a selected pdf:

  selectedPDF: "/svg/example.pdf"

(hardcoded for testing purposes)

Vuex getter:

getSelectedPDF: state => { return state.selectedPDF; } 

And here's basic component structure:

<template>
  <div>
    <pdf :src="selectedPDF"></pdf>
  </div>
</template>
<script>
import pdf from "vue-pdf";
import { mapGetters } from "vuex";
export default {
  name: "ExamplePdf",
  data: () => {
    return {};
  },
  computed: {
    ...mapGetters({
      selectedPDF: "selectedPDF"
    })
  },
  components: {
    pdf
  }
};

My idea is load pdfs in the Vuex state dynamically, and then use the example component above to display said pdf in multiple places. However, once i use the component somewhere (where it displays the pdf properly), if i try to use it somewhere else, it just displays blank page. Is it actually possible to do this with this npm module?

0 Answers
Related