In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "how to achieve dynamic routing loading in VUE". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to achieve dynamic routing loading in VUE"!
First of all, build a new vue project. Generally speaking, we will not specially deal with routing, but when there are more and more project pages, the routing configuration will become larger and larger, and the routing files will become difficult to maintain.
Import Vue from 'vue'import Router from' vue-router'import HelloWorld from'@ / components/HelloWorld'import Home from'@ / components/Home'import Test1 from'. / test1.router.js'import Test2 from'@ / components/children/Test2'import Test3 from'@ / components/children/Test3' Vue.use (Router) export default new Router ({routes: [{path:'/ HelloWorld', name:' HelloWorld', component: HelloWorld}, {path:'/', name:'Home' Component:Home, children: [{path:'/test2', name:'Test2', component:Test2,}, {path:'/test3', name:'Test3', component:Test3,}]})
This is a very simple routing file, we advanced the first step of optimization, classified by level 1 menu:
Create a new test1.router.js file and place all the routing information under the first-level menu test1
Export default {path:'/test1', name:'test1', component: () = > import ('@ / components/children/Test1'), children: []}
Component: () = > import ('@ / components/children/Test1') this is to configure the route to load lazily, and to optimize the slow loading of the first screen
Introduce this file in index.js
Import Vue from 'vue'import Router from' vue-router'import HelloWorld from'@ / components/HelloWorld'import Home from'@ / components/Home'import Test1 from'. / test1.router.js'import Test2 from'. / test2.router.js'import Test3 from'. / test3.router.js'Vue.use (Router) export default new Router ({routes: [{path:'/ HelloWorld', name:' HelloWorld', component: HelloWorld}, {path:'/', name:'Home' Component:Home, children: [Test1, Test2, Test3]}]})
To achieve this, many projects can already be satisfied, and the routing file is already very clear, but when the project is larger, it will still be unclear.
Import Vue from 'vue'import Router from' vue-router'import Home from'@ / components/Home'Vue.use (Router) let routers = [] Let getALLRouterMsg = (paths) = > {paths.keys () .forEach ((key) = > routers.push (paths (key) .default))} getALLRouterMsg (require.context ('., true,/\ .router\ .js /)) export default new Router ({routes: [{path:'/', name:'Home', component:Home, children: [... routers]}]}) so far I believe you have a deeper understanding of "how to achieve dynamic routing loading in VUE", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.