vue3 使用动态组件component


<template>
  <div @click="change">自由浏览</div>
    <component
      :is="CurrentCompoent[current]"
    ></component>
</template>
import { defineAsyncComponent, markRaw, reactive, ref } from 'vue';
const CurrentCompoent = reactive({
  TP: markRaw(defineAsyncComponent(() => import('components/TablePage/index.vue'))),
  DP: markRaw( defineAsyncComponent(() => import('components/DetailPage/index.vue')))
})
const current = ref('DP')
const change:()=>void = ()  => {
  if(current.value === "DP") {
     current.value = 'TP'
     return
  }
  if(current.value === "TP") {
    current.value = 'DP'
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM