亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

vue如何實現路由懶加載

養魚的貓咪
163
2021-05-12 18:14:48
欄目: 編程語言

在vue中實現路由懶加載的方法有:1.使用import方法實現;2.使用require.ensure()方法實現;3.使用vue異步組件實現;

vue如何實現路由懶加載

具體方法如下:

1.使用import方法實現路由懶加載

const Home = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '@/components/home.vue')

const Index = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '@/components/index.vue')

const About = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '@/components/about.vue')

const router = new VueRouter({

routes: [

{ path: '/home', component: Home },

{ path: '/index', component: Index },

{ path: '/about', component: About }

]

})

2.使用require.ensure()方法實現路由懶加載

{

path: '/home',

name: 'home',

component: r => require.ensure([], () => r(require('@/components/home')), 'demo')

}, {

path: '/index',

name: 'Index',

component: r => require.ensure([], () => r(require('@/components/index')), 'demo')

}, {

path: '/about',

name: 'about',

component: r => require.ensure([], () => r(require('@/components/about')), 'demo-01')

}

3.使用vue異步組件實現路由懶加載

{

path: '/home',

name: 'home',

component: resolve => require(['@/components/home'],resolve)

},{

path: '/index',

name: 'Index',

component: resolve => require(['@/components/index'],resolve)

},{

path: '/about',

name: 'about',

component: resolve => require(['@/components/about'],resolve)

}

0
中阳县| 滕州市| 四子王旗| 城固县| 贡山| 双城市| 三原县| 平顺县| 丹棱县| 逊克县| 昭通市| 凌海市| 凭祥市| 延长县| 清苑县| 永春县| 西充县| 盐池县| 陇西县| 肃南| 丹巴县| 浦城县| 灵川县| 通河县| 桦南县| 阿图什市| 南投县| 江口县| 如皋市| 封丘县| 双鸭山市| 兴义市| 开化县| 祥云县| 满城县| 灵川县| 瓦房店市| 体育| 上饶市| 闸北区| 铁岭县|