我真的希望有比这更好的答案,但目前这解决了问题.
在ready中,我通过this
(也可以是Vue
)访问children元素,并判断它们的名称是否符合我的预期:
ready: function() {
for (var i = 0; i < this.$children.length; i++) {
if (
this.$children[i].$options.name == 'my_component_a'
|| this.$children[i].$options.name == 'my_component_b'
|| this.$children[i].$options.name == 'my_component_c'
) {
//do stuff
}
}
}
如果之前在模板中为他们指定了引用,也可以直接访问他们:
<comp v-ref:my_component_ref></comp>
然后从Vue组件就绪:
if (this.$refs.my_component_ref){
//do stuff
}