Closed IgorHalfeld closed 10 months ago
I don't know much about nuxt except it renders on server side, this library only works on client side.
Maybe there are some directives in nuxt that allows you use client side components.
yep! @TaTo30, but usePDF
composable uses client-side apis.
it should not broke entire app when first render
Works fine with nuxt3 for me. You just need to wrap you component with <ClientOnly></ClientOnly>
tags like in this example:
ParentComponent.vue
<template>
<ClientOnly>
<ChildComponent />
</ClientOnly>
</template>
ChildComponent.vue
<template>
<VuePDF :pdf="pdf" />
</template>
<script setup>
import { VuePDF, usePDF } from "@tato30/vue-pdf";
import "@tato30/vue-pdf/style.css";
const { pdf } = usePDF("file.pdf");
</script>
Since Nuxt3 knows you only want to use this component client side he will not call usePDF on server side. Just don't do the mistake to only wrap <VuePDF :pdf="pdf" />
with <ClientOnly></ClientOnly>
in your component and call usePDF in your script, nuxt will indeed try to to call udePDF server side and you will get a server 500 error.
Hope this little explanation will help future users of nuxt and VuePDF ;)
Thanks @Suniver!, very useful example.
any plans to have a nuxt support?