异步组件

@Async
Overview
仅仅需要的时候才加载 - only load a component from the server when it's needed
使用宏 defineAsyncComponent() 定义异步组件
提高"首屏加载"速度
更多信息,请访问 Async Components
[] 标签页 - 切换时查看各组件的生命周期函数和网络加载情况
更多案例:标签页/手风琴古诗欣赏详情页轮播图一"鹿"有你
<template>
    <div>
        <button v-for="(_, tab) in tabs" @click="currentTab = tab" :key="tab"
        :class="['tab-button', { active: currentTab === tab }]">{{ tab }}</button>
        <component :is="tabs[currentTab]" class="tab"></component>
    </div>
</template>
    
<script setup>
import { defineAsyncComponent, ref } from 'vue'

const AsyncHome = defineAsyncComponent(() => import('./components/Home.vue'))
const AsyncInfo = defineAsyncComponent(() => import('./components/Info.vue'))
const AsyncTeam = defineAsyncComponent(() => import('./components/Team.vue'))
const AsyncWork = defineAsyncComponent(() => import('./components/Work.vue'))
   
const currentTab = ref('AsyncHome')
const tabs = {
    AsyncHome,
    AsyncInfo,
    AsyncTeam,
    AsyncWork
}
</script>
Homework
[] 使用条件渲染,在开发者视图 → 网络 Network 中查看异步组件的加载情况,并观察项目发布后的打包情况