gerardreches/vue-qrcode-component

document is undefined

Closed this issue · 3 comments

I used the component in nuxt.js,when I refresh the pages,it show 'document is not defined'.
The vue-qrcode-component can used in SSR?

Hi @jasmineY,

This component is build uppon davidshimjs/qrcodejs which uses document and window, these globals doesn't exist on Server Side Rendering, so the component can't be used in SSR.

That shouldn't mean that you can't use the component on your application, but you would have to register it during client side rendering, when document and window already exists.

Maybe this stackoverflow question can help you.

@gerardreches ok,I will have a try,thank you !

I know this is an old issue, but the thing that solved it for me was:

<script>
const QrCode = () => import('vue-qrcode-component')

export default {
  components: {
    QrCode,
  }
}
</script>

Source: https://deltener.com/blog/common-problems-with-the-nuxt-client-only-component/