Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

vue 3 script setup dynamic component sample

<template>
  <button @click="changeTab(CompB)">
    Change
  </button>
  <component :is="tab"></component>
</template>

<script setup>
import CompA from './CompA.vue'
import CompB from './CompB.vue'
import { ref, markRaw } from 'vue'

const tab = ref(null)

changeTab(CompA)
function changeTab (comp) {
  tab.value = markRaw(comp)
}
</script>
Source by sfc.vuejs.org #
 
PREVIOUS NEXT
Tagged: #vue #script #setup #dynamic #component #sample
ADD COMMENT
Topic
Name
5+3 =