Vue.js 2.0延迟加载

时间:2017-01-05 08:24:41

标签: javascript laravel lazy-loading vue.js chunks

我试图在Vue.js 2.0中懒惰加载我的组件(在Laravel 5.3项目中)。

根据documentation,我应该这样做:

Vue.use(VueRouter);

const Forum = resolve => require(['./Components/Forum/Forum.vue'], resolve);

export default new VueRouter({
    mode: 'history',
    routes: [

        /**
         * Forum
         */

        {
            name: 'Forum',
            path: '/forum',
            component: Forum,
            meta: { requiresAuth: true }
        }
    ]
});

但我收到很多错误:

Uncaught SyntaxError: Unexpected token <
app.js:130 Error: Loading chunk 0 failed.
    at HTMLScriptElement.onScriptComplete (app.js:84)
__webpack_require__.oe @ app.js:130
vue-router.common.js?37ec:80 [vue-router] Failed to resolve async component default: Error: Loading chunk 0 failed.

我使用Laravel Elixir这是我的gulp文件:

elixir(mix => {
    mix.webpack('app.js')
        .styles([
            './node_modules/normalize-css/normalize.css',
            './node_modules/nprogress/nprogress.css',
            './node_modules/sweetalert/dist/sweetalert.css'
            ])
        .stylus('app.styl');
});

我做错了什么?

真的会帮助我。

1 个答案:

答案 0 :(得分:0)

Laravel Elixir不支持延迟加载Vue组件。您必须升级到5.4才能获得webpack支持,或者您必须使用vue-webpack模板来构建捆绑包。