Vue3 Suspense 异步组件<Suspense>

1、异步引入组件

import { defineAsyncComponent } from 'vue';
const ChildData = defineAsyncComponent(() => import('./components/ChildData.vue'))

2、使用Suspense包裹组件,并配置好default与fallback

<template>
  <div class="app">
    <h2>app组件</h2>
    <Suspense>
      <template v-slot:default>
        <ChildData/>
      </template>
      <template v-slot:fallback>
        <h3>加载中.....</h3>
      </template>
    </Suspense>
  </div>
</template>

 

posted @ 2025-01-10 18:59  市丸银  阅读(20)  评论(0)    收藏  举报