Vue3中v-for循环遍历引入的组件为何未能加载?-灵析社区

满脑子智慧溢出

在vue3中,使用v-for循环遍历的方式无法加载组件 import OneCom from "./one-com"; import {ref} fromm vue; const comList = ref([{id: 1,comName:"OneCom "}]) 如果不通过遍历能正常加载出组件 import OneCom from "./one-com"; import {ref} fromm vue; const comList = ref([{id: 1,comName:"OneCom "}])

阅读量:137

点赞量:0

问AI
将组件本身传递给 is 而不是其名称,则不需要注册: import OneCom from './one-com.vue' import { ref, markRaw } from 'vue' const comList = ref([{ id: 1, comName: markRaw(OneCom) }]) 如果想通过名称传递则必须先对其进行注册: import OneCom from './one-com.vue' import { defineComponent, ref } from 'vue' const comList = ref([{ id: 1, comName: 'OneCom' }]) export default defineComponent({ components: { OneCom } })