Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vue-router 懒加载

开发环境:

基于Laravel 5.4 的框架,开发前后端分离的Web App

问题描述:

前端运行yarn run devyarn run watch打包后,访问站点提示如下错误:
Uncaught SyntaxError: Unexpected token <Error: Loading chunk 0 failed.at HTMLScriptElement.onScriptComplete (app.js:87)

图片描述

但是运行yarn run hot 则能正常访问!

路由定义代码如下:

import Vue from 'vue';
import Router from 'vue-router';

const Administration = resolve => require(['../views/administration/Index.vue'], resolve);
const Attendance = resolve => require(['../views/administration/Attendance/Index.vue'], resolve);
const Dormitory = resolve => require(['../views/administration/Dormitory/Index.vue'], resolve);
import NotFound from '../views/error/NotFound.vue';

import Dashboard from '../views/Dashboard.vue';

Vue.use(Router);

const router = new Router({
    mode: 'history',
    linkActiveClass: 'active',
    scrollbehavior: () => ({y: 0}),
    routes: [
        {
            path: '/',
            name: 'Dashboard',
            component: Dashboard,
            meta: {
                title: 'Dashboard | EIP',
                requiresAuth: true
            },
            children: [
                {
                    path: 'administration',
                    name: 'Administration',
                    component: Administration,
                    meta: {
                        title: 'Administration | EIP',
                        requiresAuth: true
                    },
                    children: [
                        {
                            path: 'attendance',
                            name: 'Attendance',
                            component: Attendance,
                            meta: {
                                title: 'Attendance | EIP',
                                requiresAuth: true
                            }
                        }, {
                            path: 'dormitory',
                            name: 'Dormitory',
                            component: Dormitory,
                            meta: {
                                title: '宿舍管理 | EIP',
                                requiresAuth: true
                            }
                        }
                    ]
                }
            ]
        }, {
            path: '*',
            name: 'NotFound',
            component: NotFound
        }
    ]
});

求老司机带路……


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

居然还没能解决,我也是醉了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...