I have a template loading dynamic components via their name:
<template>
<div>
<div>
<div>
<component
:is="getFormRenderer"
></component>
</div>
</div>
</div>
</template>
getFormRendererreturns a string (it comes from an API) that identifies the component by name.
All possible sub-components (in this example only telegram_send_message and time_time are imported and registered:
<script>
import { useStore } from "vuex";
import { computed } from "vue";
import exampleComponentOne from "@/components/forms/exampleComponentOne.vue";
import exampleComponentTwo from "@/components/forms/exampleComponentTwo.vue";
import defaultComponentTwo from "@/components/forms/defaultComponent.vue";
export default {
name: "ActionEditor",
setup() {
const store = useStore();
const getFormRenderer = computed(() => {
return (
store.state.level.actionSelected.plugin
);
});
return {
getFormRenderer,
};
},
components: {
exampleComponentOne,
exampleComponentTwo,
defaultComponent
},
};
</script>
Now I want to modify the dynamic <component> in a way that it defaults to defaultComponent.vue if the getFormRenderer returns a component name that does not exist.
But I can't find any way to realize this. I thought of using this.hasOwnProperty() but inside of the setup() this does is undefined.
Is there a standard way to do that?