javascript - vue.js运行时界面空白,报_vueRouter2.default is not a constructor ?
高洛峰
高洛峰 2017-04-11 12:26:54
0
2
1102

vue.js项目运行时界面空白,报_vueRouter2.default is not a constructor错误。
Uncaught TypeError: _vueRouter2.default is not a constructor

at Object.<anonymous> (router.js:24)
at __webpack_require__ (bootstrap c0f0e95…:52)
at Object.<anonymous> (entry.js:2)
at __webpack_require__ (bootstrap c0f0e95…:52)
at webpackJsonpCallback (bootstrap c0f0e95…:23)
at bundle.js:1

这个错误是什么原因导致的?为什么之前可以运行,隔了一段时间就不行了?

import Vue from 'vue';
import App from '../App.vue';
import VueRouter from 'vue-router';
import VueResource from 'vue-resource';

Vue.use(VueRouter);
Vue.use(VueResource);

import GDMap from './views/gdmap.vue'
import Admins from './views/admins.vue'
import Drivers from './views/drivers.vue'
import Vehicles from './views/vehicles.vue'
import Stations from './views/stationsTest.vue'
import Routes from './views/routes.vue'
import Frequencies from './views/frequencies.vue'
import Login from './views/login.vue'
import OrderBuses from './views/orderBuses.vue'
import OrderTravels from './views/orderTravels.vue'
import OrderCharters from './views/orderCharters.vue'
import Cities from './views/cities.vue'
import Permissions from './views/permissions.vue'
import Common from './Common.vue'

export default new VueRouter ({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    { path: '/l/:page', component: Login},
    { path: '/k/common', component: Common, children: [
        { path: '/m/:page', component: GDMap },
        { path: '/c/:page/:id(\\d+)?', component: Cities },
        { path: '/p/:page/:id(\\d+)?', component: Permissions },
        { path: '/a/:page/:id(\\d+)?', component: Admins },
        { path: '/d/:page/:id(\\d+)?', component: Drivers },
        { path: '/v/:page/:id(\\d+)?', component: Vehicles },
        { path: '/s/:page/:id(\\d+)?', component: Stations },
        { path: '/r/:page/:id(\\d+)?', component: Routes },
        { path: '/f/:page/:id(\\d+)?', component: Frequencies },
        { path: '/b/:page/:id(\\d+)?', component: OrderBuses },
        { path: '/t/:page/:id(\\d+)?', component: OrderTravels },
        { path: '/o/:page/:id(\\d+)?', component: OrderCharters },
        { path: '*', redirect: 'm/map'  }
    ]},
    { path: '*', redirect: 'l/login' }
  ]
})
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

membalas semua(2)
Peter_Zhu

检查下有没有安装babel插件

巴扎黑

在webpack配置文件webpack.config.js文件中,config={}里面有一个参数是resolve:

resolve: {
      alias: {
          'vue$': 'vue/dist/vue.js'
      }
  },

这里缺少vue-router,加进去即可。

resolve: {
      alias: {
          'vue$': 'vue/dist/vue.js',
          'vue-router$': 'vue-router/dist/vue-router.common.js'
      }
  },
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan