<template>
<div>
<AsyncComponent1></AsyncComponent1>
<!-- Render AsyncComponent2 after AsyncComponent1 -->
<AsyncComponent2></AsyncComponent2>
</div>
</template>
<script>
export default {
name: "My Component"
components: {
AsyncComponent1: () => import("./AsyncComponent1"),
AsyncComponent2: () => import("./AsyncComponent2")
}
};
</script>
我正在一个组件内异步加载两个组件,但我需要其中一个组件在另一个组件之后渲染。我想知道这是否可能?
最佳答案
将 v-if
添加到另一个组件中的 ref
。
<template>
<div>
<AsyncComponent1 ref="c1"></AsyncComponent1>
<!-- Render AsyncComponent2 after AsyncComponent1 -->
<AsyncComponent2 v-if="$refs.c1"></AsyncComponent2>
</div>
</template>
关于javascript - Vue 异步组件回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54739922/