$nextTick 获取dom undefined

<template v-for="(item,index) in comps">
  <a-tab-pane :tab="item.foName"  :key="index">
      <a-card  size="small">
          <component  :is="item.app" :ref="item.foKey"  @ok="submitOK"></component>
      </a-card>

  </a-tab-pane>
</template>

这里动态渲染组件

... http 请求
res=>{
  res.map(item=>{
      item.app = this.loadComps(item.foKey);
  })
  this.$nextTick(()=>{
      console.log(this.$refs[res[0].foKey],'----- --refs组件----')
  })
}

为啥我在$nextTick 里获取不到Dom

阅读 2.2k
1 个回答

component是子组件吗?如果是的话是因为nextTick只在当前组件dom更新后触发,并不能监听到子组件渲染完成。可以在子组件mounted中加入$emit发送渲染完成信号,父组件$on接收就行了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题