首页 > 解决方案 > 如何在 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',
  // ...
}

标签: vue.js

解决方案


推荐阅读