美文网首页
vue3 component组件动态is匹配组件

vue3 component组件动态is匹配组件

作者: Gifted_ | 来源:发表于2022-06-14 11:21 被阅读0次
<template>
  <component :is="typeComponentMap[componentId]"></component>
</template>

<script setup lang="ts">

import { useRoute } from 'vue-router'
import componentA from '引入组件'
import componentB from '引入组件'

const route = useRoute()
const componentId = route.params.type

//注意 这里写的是变量 componentA 而不是字符串 'componentA'
const typeComponentMap = { componentA, componentB }
</script>
<style lang="scss" scoped></style>

相关文章

网友评论

      本文标题:vue3 component组件动态is匹配组件

      本文链接:https://www.haomeiwen.com/subject/wthzmrtx.html