Skip to content

Instantly share code, notes, and snippets.

@coreycoburn
Last active October 26, 2022 08:54
Show Gist options
  • Save coreycoburn/525dfa7cf8de1c7d891744ced3136977 to your computer and use it in GitHub Desktop.
Save coreycoburn/525dfa7cf8de1c7d891744ced3136977 to your computer and use it in GitHub Desktop.
Dynamically load Vue components
<template>
<div>
<component :is="dynamicComponent"/>
</div>
<template>
<script>
export default {
props: {
componentName: {
type: String,
required: true
}
},
computed: {
dynamicComponent() {
return () => import(`@/components/${this.componentName}`)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment