I have a single file component Main.Vue.
I also have three other single file components A.vue, B.vue and C.vue.
I want to be able to show inside Main.Vue a different component each time. What I did was this:
<template>
<div>
<a v-if=isAVisible ></a>
<b v-if=isBVisible ></a>
</div>
</template>
<script>
import A from './A.vue';
import B from './B.vue';
...
This works but not exactly what I wanted. I wanted a different file Factory.js, which does the importing of all the components A,B,C,.. And has functions that return my component, which I can use somehow in Main.vue. Here's what I tried Factory.js to look like:
import A from './A.vue';
import B from './B.vue';
function getComponent(){
if (..)
return new A();
else if (..)
return new B();
...
}
This didn't work at all.
I want the factory file approach because:
1) I want to split it to different factory files
2) I want to Attach data to each component. So I'll have an object that contains the function returning the actual component + some additional data like name
Any ideas how to do this?