2022-06-29

Can't load components using VueJS

I'm trying to use dynamic import but nothing is happening

this is my code :

<component :is="state.name"/>
<button @click="onClick">Click me !</button>

setup() {
  const state = reactive({
  name: computed(() => isShow.value == true ? import('./b.vue'): import('./a.vue'))
  });

  const isShow = ref(false);
  const onClick = () => {
    console.log(5)
    isShow.value = true;
  }

  return {
    state,
    onClick
  }
},

and here is my b & a components

b
<script>
export default {
    data(){},
    created(){
        alert('lol')
    }
}
</script> 

Please I need a help to load my components programatically



No comments:

Post a Comment