我正试图通过名字访问一个特定的子元素.现在,因为子元素在哪里,我用这个称呼子元素:
this.$root.$children[0]
只要子元素总是[0]
岁就可以了,但如果有一种方法可以做到:
this.$root.$children['detail']
我一直在想$refs
可能是我问题的答案,但却永远找不到一种方法来帮助我.
有什么 idea 吗?
我正试图通过名字访问一个特定的子元素.现在,因为子元素在哪里,我用这个称呼子元素:
this.$root.$children[0]
只要子元素总是[0]
岁就可以了,但如果有一种方法可以做到:
this.$root.$children['detail']
我一直在想$refs
可能是我问题的答案,但却永远找不到一种方法来帮助我.
有什么 idea 吗?
你说的这个子元素真的是你想从中访问它的组件的子元素吗?在这种情况下,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