在Vue 2.0应用程序中,假设我们有组件A,B和C.
声明,注册和使用B.
是否有可能将C从A传递给B?
像这样的东西:
<template>
<div class="A">
<B :child_component="C" />
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
并以某种方式在B中使用C.
<template>
<div class="B">
<C>Something else</C>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
动机:我想创建一个通用组件B,用于A但从A其子级接收C.实际上A会B多次使用不同的'C'来表示它.
如果这种方法不正确,在Vue中这样做的正确方法是什么?
回答@Saurabh
而不是作为道具传递,我尝试了B.内部的建议.
<!-- this is where I Call the dynamic component in B -->
<component :is="child_component"></component>
//this is what I did in B js
components: {
equip: Equipment
},
data () {
return {
child_component: 'equip',
_list: []
}
}
Run Code Online (Sandbox Code Playgroud)
基本上我试图渲染设备,但动态的方式
我在控制台和空白页面中收到3个错误
[Vue警告]:在/home/victor/projetos/tokaai/public/src/components/EquipmentFormItem.vue中渲染组件时出错:
未捕获的TypeError:无法读取未定义的属性"name"
TypeError:无法读取undefined的属性'setAttribute' …