I'm building my VUEJS app which I can see preview of pdf file, and this pdf I get from an API and store it in VUEX. But somehow I can't see the pdf preview
store/index.js
export default new Vuex.Store({
state: () => ({
document: null
)},
mutations: {
getDocument(state, document) {
state.document = document
}
},
actions: {
async fetchDocument({ commit }) {
const res = await axios.get('url/test.pdf')
commit('getDocument', res.data)
}
},
getters: {
allDocument(state) {
return state.document
}
}
})
PdfPreview.Vue
<template>
<iframe :src='getPDF' height="680px" width="1108px"></iframe>
</template>
<script>
computed: {
...mapGetters[('allDocument')],
//not sure with this getPDF func
getPDF() {
return this.allDocument
}
},
methods: {
...mapActions[('fetchDocument')]
},
main.js
mounted() {
this.$store.dispatch('fetchDocument')
how do I approach this? to show pdf in iframe from API through VUEX, I have to fetch it and use VUEX, because it will be used more often, and my boss said so