vue.js - 如何在 VueJS 中枚举特定组件类型的子虚拟机?
问题描述
VueJS $children提供了一个包含所有 Vue 组件的数组。
我只想遍历特定类型的组件,但我找不到从对象中获取每个孩子的“名字”的方法!
例如
export default {
name: 'mainapp',
components: { Component1, Component2 },
methods: {
doSomething() {
for (c of this.$children) {
if (c IS Component1) ... // ← how to do this?
}
}
}
}
并且 component1 可能包括
export default {
name: 'Component1',
// ...
}
解决方案
推荐阅读
- mongodb - MongoDB聚合查询数组中的值
- wpf - 如何使用 XAML 为 TabControl 中的每个 TabItem 创建单独的 UserControl 实例?
- ios - 如何在不改变世界坐标中的相对位置、大小和比例的情况下将 SCNNode 作为子节点添加到父节点
- ls - ls 命令中 --file-type 的作用是什么
- spring-webflow - 春季网络流。从按钮传递值
- syntax - pyodbc 驱动程序关键字语法错误
- javascript - Mongoose 在两个参数中搜索一个值
- java - 如何以毫秒为单位将时间转换为 ZonedDateTime
- mysql - MySQL SELECT 查询中的内部操作顺序
- xslt - 将日期格式从 YYYY-MM-DD (2018-08-21) 转换为 MMM-DD-YYY (Aug-21-2018)