vue3.0+vite2實(shí)現(xiàn)動態(tài)異步組件懶加載
創(chuàng)建一個vite項目
性能決定成敗;vite確實(shí)快;
cmd 命令行(默認(rèn)你已經(jīng)安裝了node & npm),執(zhí)行npm init @vitejs/app vue-study – --template vue;
cd至vue-study,npm install(安裝依賴); npm run dev(啟動項目);
創(chuàng)建組件
新建一個目錄為pages,pages下面再新建一個目錄contents,contens下面可以新建具體的組件目錄頁面,此時目錄結(jié)構(gòu)為

App.vue
<template>
<p @click="onChangeContents('./pages/contents/gp/gp.vue')">郭培</p>
<p @click="onChangeContents('./pages/contents/systemManges/xtcs.vue')">系統(tǒng)參數(shù)</p>
<p>{{currentTabComponent}}</p>
<!-- <Suspense> -->
<component :is="DefineAsyncComponent({
// 工廠函數(shù)
loader: Modeuls[currentTabComponent],
// // 默認(rèn)值:Infinity(即永不超時,單位 ms)
timeout: 3000,
})"></component>
<!-- </Suspense> -->
</template>
<script lang="ts">
import {
defineComponent,
defineAsyncComponent,
reactive,
ref
} from 'vue'
export default defineComponent({
name: 'App',
setup() {
//vite加載指定路徑的所有模塊
const Modeuls = import.meta.glob('./pages/contents/*/*');
const onChangeContents = function(URL) {
currentTabComponent.value = URL;
console.log(currentTabComponent)
}
let currentTabComponent = ref('./pages/contents/systemManges/xtcs.vue');
const DefineAsyncComponent = defineAsyncComponent;
return {
DefineAsyncComponent,
currentTabComponent,
onChangeContents,
Modeuls
}
},
})
</script>
到此這篇關(guān)于vue3.0+vite2實(shí)現(xiàn)動態(tài)異步組件懶加載的文章就介紹到這了,更多相關(guān)vue3.0+vite2動態(tài)異步懶加載內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談Vue.js中ref ($refs)用法舉例總結(jié)
本篇文章主要介紹了淺談Vue.js中ref ($refs)用法舉例總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12
Vue中el-tree樹全部展開或收起的實(shí)現(xiàn)示例
本文主要介紹了Vue中el-tree樹全部展開或收起的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
vue2如何實(shí)現(xiàn)vue3的teleport
這篇文章主要介紹了vue2如何實(shí)現(xiàn)vue3的teleport,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
詳解解決使用axios發(fā)送json后臺接收不到的問題
這篇文章主要介紹了詳解解決使用axios發(fā)送json后臺接收不到的問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06

