小编bor*_*rna的帖子

懒加载Vue的父组件和所有嵌套的路由

我有延迟加载嵌套路由的问题!

这是我的父路线:

import ChildRoutes from "app/modules/child.route”;

routes: [
    {
        path: '/child',
        component: resolve => require(['app/modules/root'], resolve),
        children: ChildRoutes
    }
]
Run Code Online (Sandbox Code Playgroud)

而我的child.route.js

import ChildHome from …
import ChildContact from …

export default [
    {
        path: '',
        name: 'childHome',
        component: ChildHome
    },
    {
        path: 'about',
        name: 'childAbout',
        // doesn’t work
        component: resolve => require(['./components/about.vue'], resolve)
    },
    {
        path: 'contact',
        name: 'childContact',
        // this one doesn’t work as well
        component: ChildContact
    },
    ...
]
Run Code Online (Sandbox Code Playgroud)

当然,第一个子路由 ( childHome) 会自动工作,但之后我只会得到没有渲染组件的空白页面!如果我懒惰地加载父母和孩子,一切都会好起来的!

我究竟做错了什么?

值得一提的是我的项目使用 …

lazy-loading vue.js vue-router vuex

7
推荐指数
1
解决办法
1397
查看次数

标签 统计

lazy-loading ×1

vue-router ×1

vue.js ×1

vuex ×1