获取递归组件中异步函数执行后的组件vue实例

父组件

  async getChildComponentInstances() {
      for (let i = 0; i < this.newshowTree.length; i++) {
        const value = this.newshowTree[i]
        // console.log(value)
        if (i == 0) {
          this.traverse(this.$refs.rootComponent)
//在这里traverse函数是获取根组件的子组件实例
//    traverse(component) {
//      if (component !== undefined) {
//            this.childComponentInstances.push(component)
//         }
//      },
        }
        //当前的组件下的子组件的vue实例
        let treeSon = this.childComponentInstances
        for (let j = 0; j < treeSon.length; j++) {
          treeSon[j].isOpen = false
          if ('model' in treeSon[j]) {
            if (value == treeSon[j].model.id) {
//调用我们需要找到的哪个组件的autoExpand()函数
              await treeSon[j].autoExpand()
              if (treeSon[j].$children.length > 0) {
                this.childComponentInstances = []
//获取到这个组件下的子组件实例
                treeSon[j].$children.forEach((child) => {
                  this.childComponentInstances.push(child)
                })
                // console.log(this.childComponentInstances)
              }
            }
          }
        }
      }
    },

子组件如下,是个只包含自己的递归组件

<template>
  <li>
    <ul class="de-animate-wrap" v-show="isOpen">
      <TreeItem v-for="(item, index) in childNode" :key="index" class="item" :model="item" />
    </ul>
  </li>
</template>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值