vue路由懒加载(延迟加载)的写法..

路由懒加载可以帮我们在进入首屏时不用加载过度的资源,从而减少首屏加载速度

(1)路由文件中,非懒加载写法:

import Index from '@/page/index/index';
export default new Router({  
    routes: [    
        { 
            path: '/', 
            name: 'Index',     
            component: Index 
        }
    ]
})

(2)路由懒加载写法:

export default new Router({
  routes: [    
        { 
            path: '/', 
            name: 'Index', 
            component: resolve => require(['@/view/index/index'], resolve) 
        }
   ]
})
posted @ 2022-10-06 06:49  Mahmud(مەھمۇد)  阅读(246)  评论(0编辑  收藏  举报