defineAsyncComponent( )
定義一個異步組件,它在運(yùn)行時是懶加載的。參數(shù)可以是一個異步加載函數(shù),或是對加載行為進(jìn)行更具體定制的一個選項(xiàng)對象。在大型項(xiàng)目中,我們可能需要拆分應(yīng)用為更小的塊,并僅在需要時再從服務(wù)器加載相關(guān)組件。Vue 提供了 defineAsyncComponent 方法來實(shí)現(xiàn)此功能:
<div class="box" >
<component :is="aa"></component>
</div>
<script>
import { defineAsyncComponent } from 'vue'
computed: {
aa () {
this.xxxx = '組件名’
return AsyncComp (() => import(`../components/comps/${this.xxxx}.vue`))
}
<script>