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' }
]
})
检查下有没有安装babel插件
在webpack配置文件webpack.config.js文件中,config={}里面有一个参数是resolve:
这里缺少vue-router,加进去即可。