日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue路由 routers的写法:require用与不用

發(fā)布時間:2025/3/14 vue 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue路由 routers的写法:require用与不用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

vue路由的寫法有很多種,這里我只說routers的寫法,一種是compcomponent后面直接寫路徑,另一種是用require的方式,來看代碼

import Vue from 'vue' import Router from 'vue-router' //首頁================== //import index from '@/components/index' //產(chǎn)品中心================ import productCenter from '@/components/productCenter/productCenter.vue' //商務(wù)合作================== import teamwork from '@/components/teamwork/teamwork.vue' //咨詢中心================= import askCenter from '@/components/askCenter/askCenter.vue' //關(guān)于中棋================== import aboutUs from '@/components/aboutUs/aboutUs.vue'Vue.use(Router)export default new Router({routes: [//首頁{path: '/',name: 'index',component:resolve =>require(['index'],resolve)}//產(chǎn)品中心,{path: '/productCenter',name: 'productCenter',component: productCenter}//商務(wù)合作,{path: '/teamwork',name: 'teamwork',component: teamwork}//咨詢中心,{path: '/askCenter',name: 'askCenter',component: askCenter}//關(guān)于我們,{path: '/aboutUs',name: 'aboutUs',component: aboutUs}] })

首先先說明一點(diǎn),import引入時用到的“@”就相當(dāng)于“..”;

第二點(diǎn),重點(diǎn)來了,我們看到index頁面是用的require的方式寫的路由,所以上面的import就注釋掉了,這種寫法的好處,不僅僅是簡單,還有這樣寫是按需加載,訪問此路由時才加載這個js,會避免進(jìn)入首頁時加載內(nèi)容過多,因?yàn)閕mport引入,當(dāng)項(xiàng)目打包時路由里的所有component都會打包在一個js中,而用require會將你的component分別打包成不同的js。

轉(zhuǎn)載于:https://www.cnblogs.com/eyed/p/9606277.html

總結(jié)

以上是生活随笔為你收集整理的vue路由 routers的写法:require用与不用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。