封装组件的时候报错Unknown custom element: router-view make sure to provide the name option.

在配置项目路由时,使用router-view 不能正常渲染,报错如下:[Vue warn]: 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

检查如下路由配置文件index.js:

import Vue from 'vue
import VueRouter from 'vue-router'

//懒加载
const Home=()=>import('../views/home/Home.vue')
const Category=()=>import('../views/category/Category.vue')
const Cart=()=>import('../views/cart/Cart.vue')
const Profile=()=>import('../views/profile/Profile.vue')

Vue.use(VueRouter)

const routes=[
  {
    path:'',
    redirect:'/home'
  },
  {
    path:'/home',
    component:Home
  },
  {
    path:'/category',
    component:Category
  },
  {
    path:'/cart',
    component:Cart
  },
  {
    path:'/profile',
    component:Profile
  },

]
const router =new VueRouter({
  routes
})
export default router

编写正确,之后在请教了群里的老哥们后,发现入口文件main.js中

import Vue from 'vue'
import App from './App'


Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',

  render: h => h(App)
})


忘了注册组件了!!!!

修改后如下:

import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

这种无脑的小错误希望自己不要再犯了。

封装组件的时候报错Unknown custom element: router-view   make sure to provide the name option.封装组件的时候报错Unknown custom element: router-view   make sure to provide the name option. 七彩毛毛虫 发布了2 篇原创文章 · 获赞 0 · 访问量 23 私信 关注
上一篇:Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS


下一篇:[ALSA架构][ASOC架构][第七话]如何写ALSA app 程序