component的is写法优化

<template>
  <component :is='component'></component>
  </template>
 
  <script setup lang='ts'>
  import { ref, shallowRef } from 'vue'
  import A from './A.vue'
 
  // 直接通过这种形式还是会有数据劫持,但是没有必要,因此会有警告
  // const component = ref(A)
 
  // 用通过shallowRef来解决数据劫持的问题
  const component = shallowRef(A)
 
  </script>
 
  <style scoped lang='scss'>
 
  </style>

posted on 2025-02-04 16:38  ChoZ  阅读(11)  评论(0)    收藏  举报

导航