I need to check for the existence of a component before dynamically displaying it in Nuxt. The component name is based on a route slug, therefore I can't know in advance if the component name is valid.
If there's no component for the slug, I would like to display a text using v-else. (see markup)
However, I'm not able to infer whether the component is available or not as return value is always a function.
<component :is="componentDynamic" v-if="componentDynamic" />
<h1 v-else>Component Not available</h1>
import Vue from 'vue'
export default Vue.extend({
computed: {
componentDynamic() {
const componentName = this.$route.params.slug,
const result = async () => await import(`@/components/${componentName}`)
console.log(result)
return result
},
},
})