[Vuejs]-Vue.js Toggle vuecomponents

0👍

Give a try to that one: https://vuejs.org/guide/essentials/component-basics.html#dynamic-components

Mainly like here: https://stackoverflow.com/a/73029625/8816585

<script setup>
import { ref } from "vue"

import Hehe from "@/components/Hehe.vue"
import Nice from "@/components/Nice.vue"

const boolean = ref(true)
</script>

<template>
  <component :is="boolean ? Hehe : Nice" />
  <button @click="boolean = !boolean">toggle</button>
</template>

Leave a comment