【src/router/index.js】
import Vue from 'vue';
import VueRouter from 'vue-router';
// 无论组件有没有用,都会被加载
import SectionA from '../views/SectionA';
import SectionB from '../views/SectionB';
import SectionC from '../views/SectionC';
// 组件按需加载
const SectionA = (callback) => import('../views/SectionA').then( module => callback(module))
Vue.use(VueRouter)
const router = new Router({
routes: [
{ path: '/', redirect: SectionA },
{ path: '/sectionA', component: SectionA },
{ path: '/sectionB', component: SectionB },
{ path: '/sectionB', component: SectionC }
]
})
export default router;
Vue 组件按需引入
最新推荐文章于 2024-02-19 17:39:28 发布