vue使用vue-router报错

报错1.

app.js:172 Uncaught TypeError: vue_router__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor
at eval (index.js:4:1)
at ./src/router/index.js (app.js:108:1)
at webpack_require (app.js:169:33)
at fn (app.js:442:21)
at eval (main.js:7:71)
at ./src/main.js (app.js:97:1)
at webpack_require (app.js:169:33)
at app.js:1367:109
at webpack_require.O (app.js:223:23)
at app.js:1368:53

1. 原因一是引入错误,一下是正确示范

main.js

import Vue from 'vue'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import router from './router'

import App from './App.vue'
Vue.use(ElementUI);
new Vue({
  router, // 确保将路由器实例绑定到Vue实例上
  render: h => h(App),
}).$mount('#app')

router.js

import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const homeRoutes = new Router({
  routes: [
    
   
  ]
})
export default homeRoutes
2. 确定引入正确就是版本号不对

vue-router@4 使用vue3。 vue2使用vue-router@3

卸载:npm uninstall vue-router
安装:npm i vue-router@3

报错2.

vue.runtime.esm.js:4605 [Vue warn]: Unknown custom element:

是main.js文件中router引入不对,请对比问题一中的第一条修改

报错3.

vue.runtime.esm.js:4605 [Vue warn]: Error in render: "TypeError: Cannot read

是main.js文件中router引入不对,请对比问题一中的第一条修改

你可能感兴趣的:(报错收录集合,vue.js,前端,javascript)