隐菌子 2022-08-11 20:45 采纳率: 58.3%
浏览 340

vue3 无法querySelectorAll获取异步组件?

我有两个异步组件

const anchorPoint = defineAsyncComponent(() => import('@/layout/components/anchorPoint/anchorPoint.vue'));

const fieldset = defineAsyncComponent(() => import('@/components/fieldset/fieldset.vue'));

第一个是锚点组件,我需要在他内部去判断fieldset中一些元素的滚动情况,
所以使用了querySelectorAll,但我发现由于异步的原因我无法获取到dom

onMounted(async () => {
  await nextTick();
  const NodeList = document.body.querySelectorAll(props.anchor);
  console.log('0000000000000', NodeList); //为空
 ........
  renderAnchor(NodeList);
});

请问我该如何解决这个问题?

  • 写回答

1条回答 默认 最新

  • Z_ One Dream 2022-08-12 10:02
    关注

    你说的这个问题应该不在这里,props.anchor 这个的保证写的是对的,页面有这个东西才行,

    评论

报告相同问题?

问题事件

  • 创建了问题 8月11日