IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    vuejs为什么按需加载的模块在开发环境下,正常加载,但是,打包后在生产环境下却不能加载?

    webcainiao发表于 2017-04-17 02:23:11
    love 0

    我在Vue路由设置中想按需加载一个notfound的页面,但是,生产环境下,总是加载不上。

    //使用组建模式,引入vue,vue-router,然后调用vue.use(vue-router)
    import Vue from 'vue';
    import VueRouter from 'vue-router';
    //引入路由组件
    import Index from  '../views/index/index';
    import User from '../views/user/user';
    // import NotFound from '../views/notfound';
    const NotFound = function(r){
    	return require.ensure([],function(){
    			return r(require('../views/notfound.vue'));
    		},'NotFoundChunk')
    };
    
    //调用
    Vue.use(VueRouter);
    
    //定义路由,每个路由映射一个组件
    const routes = [
    	{
    		component: Index,
    		path: '/'
    	},
    	{
    		component: User,
    		path: '/user/:id'
    	},
    	{
    		component: NotFound,
    		path: '*'
    	}
    ]
    
    //导出路由实例,传入routes。此路由实例可在入口文件里作为配置参数添加在vue实例中,并在vue实例上挂载根元素
    export default new VueRouter({
    	mode: 'history',
    	routes:routes,//可简写routes
    })
    

    这是我的github地址: (https://github.com/webcainiao/learn_vue/tree/master/project1) 我实在搜不到解决的方法了,求解,谢谢



沪ICP备19023445号-2号
友情链接