gerardreches / vue-qrcode-component

Create QR codes with a simple Vue component
https://gerardreches.github.io/vue-qrcode-component/
MIT License
124 stars 21 forks source link

document is undefined #4

Closed jasmineY closed 7 years ago

jasmineY commented 7 years ago

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?

gerardreches commented 7 years ago

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.

jasmineY commented 7 years ago

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

MarcelloTheArcane commented 2 months ago

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/