我正在尝试按名字访问特定的孩子。目前,由于孩子所在的位置,我这样称呼孩子:
this.$root.$children[0]
没关系,只要那个孩子总是[0]
但如果有一种方法可以做类似的事情那就太好了:
this.$root.$children['detail']
我一直在想$refs
可能是我问题的答案,但永远找不到帮助我的方法。
有任何想法吗?
您正在谈论的这个孩子真的是您想要从中访问它的组件的孩子吗?在这种情况下,v-ref
确实是答案:
// in the code of the parent component, access the referenced child component like this:
this.$refs.detailsChild
<!-- Template of the parent component, assuming your child Component is called Details -->
<details v-ref:details-child></details>
相关API文档:http://vuejs.org/api/#v-ref http://vuejs.org/api/#v-ref
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)