Closed NanyThery closed 4 years ago
Hmm can I see your file in this directory: ~/plugins/vue-html2pdf.js
?
It should look like this:
// vue-html2pdf.js
import Vue from 'vue'
import VueHtml2pdf from 'vue-html2pdf'
Vue.use(VueHtml2pdf)
Hi! Thanks for your reply,
Yes, this is what I have in my plugin file:
import Vue from 'vue'
import VueHtml2pdf from 'vue-html2pdf'
Vue.use(VueHtml2pdf)
Also tried with import * as VueHtml2pdf, but no results
Weird, the error says that the vue-html2pdf component is not registered, but im not seeing anything wrong on your code.
I uploaded the nuxt project I test on try have a look on it: https://github.com/kempsteven/nuxt-tester/tree/main
Thank you so much for the time you put into this. I'll give you feedback as soon as I can test it. Thanks again.
Hi again!
An update on this. I did the following and even having copied directly your page and component, still, throws me the error of "have you registered the component"?. 1) Copied exactly the same line in nuxt.config plugins. 2) Installed Babel-core, since I noticed you had it in your package and I didn't 3) I copied and pasted your pages/index and also your content-pdf component in my project to test it as is.
Still getting the same error. I am not really sure what it is.
But if it is working in your naked project, there must be something I've installed interfering with the app... I googled a lot but couldn't find anything that puts me in the right direction. I think I've tried all the combinations possible.
I am using Nuxt 2.14, but I don't think it's relevant for the case.
Thank you again for your time.
Kind regards,
Nadine
Hello, I'm not exactly sure whats wrong, the main issue is that the component is not registering.
I tried replicating this in a couple of nuxt application types (SSR and JAMStack), still no success in replicating the issue. You could try implementing this in a new nuxt application and compare the two projects and see what could have been the issue.
Good luck!
Hello again!
I could finally manage it to work.
1) Component not registered. It seems there was an issue with the packages. Cannot tell which exactly. But it was just ignoring it. So I solved that issue by doing: npm install npm audit fix
On the other hand, and not directly related with this issue:
2) I wanted the pdf download to start as soon as the URL loaded, so I put the generatePDF() function within the mounted() hook. This resulted in an error because the child components were not ready. So I had to implement the $nextTick() function. So, if anyone wants to download a PDF on mounted, yo need to do something like this:
async fetch() {
this.activeMenu = this.$store.state.activeMenu
},
mounted() {
this.$nextTick(() => this.print())
},
methods: {
print() {
this.$refs.html2Pdf.generatePdf()
},
},
More doc on this:
Maybe it could help to put also this use case in the docs for newbies like me. hehe.
Issue solved :D Thanks again for your support.
Regards,
Cool :D
Could you please make a replicate of the current demo in Nuxt? I just cannot make it work following the instructions.
1) I've made the plugin file. 2) I've included as a plugin with mode: 'client' 3) I created a component with the options and the content and wrapped it into a "client-only" tag. 4) called the generate PDF
The component:
The nuxt config:
The errors:
What I've tried:
I really do not know what else to do, can you please help me? I don't seem to find any other example on how to apply it in Nuxt.
Thank you