等待异步组件时渲染一些额外内容,让应用有更好的用户体验。
1.异步引入组件
import { defineAsyncComponent } from 'vue'
const Child = defineAsyncComponent(()=>import('@/views/Child.vue'))
2.使用Suspense包裹组件,并配置好default与fallback
<template>
<Suspense>
<template v-slot:default>
<Child/>
</template>
<template v-slot:fallback>
<h3>加载中...</h3>
</template>
</Suspense>
</template>