vue-router使用是报错. TypeError: Cannot read properties of undefined (reading ‘matched‘)
vue-router报错TypeError: Cannot read properties of undefined (reading ‘matched‘)
·
使用vue-router后,运行vue项目报错:
原代码:
import Vue from 'vue'
import App from './App.vue'
import VueRouter from "vue-router"
import routers from "./router/index"
Vue.config.productionTip = false;
Vue.use(VueRouter);
// router传参错误
new Vue({
routers,
render: h => h(App),
}).$mount('#app');
发现,自定义的路由文件导入必须用router来接收
修改后代码
import Vue from 'vue'
import App from './App.vue'
import VueRouter from "vue-router"
// 变量名只能用router
import router from "./router/index"
Vue.config.productionTip = false;
Vue.use(VueRouter);
// router <==> router: router
new Vue({
router,
render: h => h(App),
}).$mount('#app');
更多推荐
已为社区贡献1条内容
所有评论(0)