【发布时间】:2017-12-19 18:19:59
【问题描述】:
我正在尝试构建一个表格组件。
我想为网格定义列元数据并将其作为数组道具传递,并将实际数据作为另一个道具传递给网格。
我能够毫无问题地实现这一目标。
但是,现在我想传递一个动态组件作为每个列定义的一部分,以便用户可以定义/控制单元格的呈现方式(在同一单元格中带有编辑删除按钮的内容等)
有没有办法将动态组件作为道具传递,然后渲染该组件?
<parent-comp>
<tr class="" v-for="result in dataSource">
<template v-for="column in columns">
<td>
<template v-if="column.customComponent">
######## How do I render this customComponent ########
</template>
</td>
</template>
</tr>
</parent-comp>
dataSource 数据可能是这样的
[
columns: [{
name: "something",
customComponent: SomeCustomComponent
}, {
name: "another thing",
customComponent: AnotherOtherCustomComponent
}]
]
如果上述问题不清楚,我们很乐意对此进行详细说明/澄清。
【问题讨论】:
-
@thanksd 谢谢,但在我的情况下,我不会事先将哪些组件传递给 parent-comp 以将组件列在
components属性中 -
如果你通过了组件定义就不需要了。
-
这是our discussion最后一次出现。
标签: vuejs2 vue-component