If we have components A, B, and C in a Vue 2.0 app,
A declares, registers, and uses B.
Can we pass C from A to B?
For example:
<template>
<div class="A">
<B :child_component="C" />
</div>
</template>
Then use C in B somehow:
<template>
<div class="B">
<C>Something else</C>
</div>
</template>
The idea is to create a generic component B
used by A
, but with different 'C's passed to it.
If this method is not correct, what is the proper way of achieving this in Vue?
Answering @Saurabh
Instead of passing as props, I tried implementing the suggestion inside B.
<!-- calling the dynamic component in B -->
<component :is="child_component"></component>
// js code in B
components: {
equip: Equipment
},
data () {
return {
child_component: 'equip',
_list: []
}
}
I am attempting to render Equipment dynamically, but encountering console errors and a blank page:
[Vue warn]: Error when rendering component at /home/victor/projetos/tokaai/public/src/components/EquipmentFormItem.vue:
Uncaught TypeError: Cannot read property 'name' of undefined
TypeError: Cannot read property 'setAttribute' of undefined
It seems like there may be an issue in my implementation.