V-if 组件不渲染dom节点

图片
子组件是tool,如果不加v-if就正常,加了v-if后可以执行子组件钩子函数,但是找不到dom节点,请问如何解决,谢谢

If you want the DOM still exists, using v-show.

v-show is like setting CSS display to none. So the DOM still exists, but you can’t see it.
v-if is like using javascript to set element to remove from tree that you specified.

tool组件没写dom元素

thanks for reply,but in my project,i need to use “v-if”,because i have to prepare the data which used by the “tool” component in an async function,if i use v-show to render the “tool” component,it would cause complex problem

因為你給的資訊太少了 不過如果是async的問題 可以用這種方式解掉 不一定要註冊在tool上面

<template v-if="asyncLoadingComplete">
  <tool v-show=""></tool>
</template>

async loading() {
  this.asyncLoadingComplete = false;
  const res = await axios.get('/todo');
  this.asyncLoadingComplete = true;
}