<script setup lang="ts"> // 传组件对象的用法 import { ref, reactive } from 'vue' import A from "@/components/A.vue" import B from "@/components/B.vue" import C from "@/components/C.vue"
const comId = ref(A) const active = ref(0)
const data = reactive([ { name: "A组件", com: A }, { name: "B组件", com: B }, { name: "C组件", com: C }, ])
<script setup lang="ts"> import { ref, reactive, markRaw, shallowRef } from 'vue' import A from "@/components/A.vue" import B from "@/components/B.vue" import C from "@/components/C.vue"
// 使comId响应式只达到.value这一层 const comId = shallowRef(A) const active = ref(0)
// explicit self name has highest priority if (type === COMPONENTS) { const selfName = getComponentName( Component, false/* do not include inferred name to avoid breaking existing code */ ) if ( selfName && (selfName === name || selfName === camelize(name) || selfName === capitalize(camelize(name))) ) { returnComponent } }
// res是当前要切换的组件 const res = // local registration // check instance[type] first which is resolved for options API // 局部注册 resolve(instance[type] || (ComponentasComponentOptions)[type], name) || // global registration // 全局注册 resolve(instance.appContext[type], name)
if (!res && maybeSelfReference) { // fallback to implicit self-reference returnComponent }
if (__DEV__ && warnMissing && !res) { const extra = type === COMPONENTS ? `\nIf this is a native custom element, make sure to exclude it from ` + `component resolution via compilerOptions.isCustomElement.` : `` warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`) }
// 返回组件 return res } elseif (__DEV__) { warn( `resolve${capitalize(type.slice(0, -1))} ` + `can only be used in render() or setup().` ) } }