我有下一个模板:
<TableComponent>
<TableColumn v-bind:field="'firstName'" v-bind:label="'First Name">
</TableColumn>
我如何获得TableColumn
的组件实例?
在TableComponent上,我有下一个mounted
方法:
mounted () {
const columnComponents = this.$slots.default
.filter(column => column.componentInstance)
.map(column => column.componentInstance)
console.info(columnComponents)
},
但是在控制台信息上,我得到了一个空数组。我如何获得TableColumn
道具?
答案 0 :(得分:0)
使用ref
<TableComponent>
<TableColumn ref="tableColumn" v-bind:field="'firstName'" v-bind:label="'First Name">
</TableColumn>
然后
mounted() {
this.$nextTick(() => {
const col = this.$refs.tableColumn;
});
}