Created
April 3, 2021 19:04
-
-
Save james2doyle/b8d1723778691055c87d627dbba39f03 to your computer and use it in GitHub Desktop.
Fix issue with external library that calls window in Nuxt/Vue when being server rendered by dynamically swapping it in the client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<component :is="component" /> | |
</template> | |
<script> | |
export default { | |
name: 'DynamicComponentForBrowser', | |
data() { | |
return { | |
component: 'div', | |
}; | |
}, | |
async fetch() { | |
// the component uses `window` so we only want to | |
// render the real component when in the browser | |
this.component = (await import('@some-person/special-input')).SpecialInput; | |
}, | |
fetchOnServer: false, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment