vue3.0+vite2實現(xiàn)動態(tài)異步組件懶加載
性能決定成敗;vite確實快;cmd 命令行(默認你已經(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], // // 默認值: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實現(xiàn)動態(tài)異步組件懶加載的文章就介紹到這了,更多相關(guān)vue3.0+vite2動態(tài)異步懶加載內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明3. CSS hack用法案例詳解4. PHP設(shè)計模式中工廠模式深入詳解5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. ASP+ajax實現(xiàn)頂一下、踩一下同支持與反對的實現(xiàn)代碼7. .NET中l(wèi)ambda表達式合并問題及解決方法8. ThinkPHP5實現(xiàn)JWT Token認證的過程(親測可用)9. asp中response.write("中文")或者js中文亂碼問題10. JSP數(shù)據(jù)交互實現(xiàn)過程解析
