javascript - Vue.js $children 按组件名称

标签 javascript vue.js web-frameworks

我正在尝试按名称访问特定的 child 。目前,由于 child 所在的位置,我是这样称呼 child 的:

this.$root.$children[0]

只要那个 child 总是 [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

关于javascript - Vue.js $children 按组件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35769139/

相关文章:

javascript - 如何将我的代码重构为游戏循环?

javascript - 当在浏览器中重新加载 URL 到定义的路由器路由时出现 404

javascript - jQuery.on() 是如何工作的?

html - Vuetify v-data-table固定 header 不起作用

javascript - 模板中的 VueJS 绑定(bind)类不起作用

python - 如何在 Pyramid 中通过 POST 提交请求?

javascript - 如何在单击删除按钮时中止删除记录?

vue.js - 在 Vue 组件中定义用户定义的 getter

java - JSF 与条纹,哪个最好?

java - 与 PHP 5.4 相比,Java Web 应用程序内存和 CPU 使用率有多高