Vue报错:Unknown custom element: router-view - did you register the component correctly

vue-router应用到组件中时报错:
Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the “name” option.

found in

—> at src/App.vue

main.js
Vue报错:Unknown custom element: router-view - did you register the component correctly_第1张图片
router.js
Vue报错:Unknown custom element: router-view - did you register the component correctly_第2张图片
app.vue
Vue报错:Unknown custom element: router-view - did you register the component correctly_第3张图片
1.先检查路由文件中有没有 Vue.use(VueRouter); 要把router注入到vue里
①可以在router.js中写Vue.use(VueRouter); 要导入Vue(import Vue from ‘vue’)
②也可以在main.js中写 Vue.use(VueRouter),要导入VueRouter
(import VueRouter from ‘vue-router’)
2.有 Vue.use(VueRouter)还是报错,检查main.js文件中是否配置路由

main.js
Vue报错:Unknown custom element: router-view - did you register the component correctly_第4张图片
配置之后,报错消失,出现新的报错:Vue is not defined
Vue报错:Unknown custom element: router-view - did you register the component correctly_第5张图片
检查router文件,是否导入vue
在router.js中加 import Vue from ‘vue’,报错解决

你可能感兴趣的:(Vue报错:Unknown custom element: router-view - did you register the component correctly)