在配置项目路由时,使用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)
})
这种无脑的小错误希望自己不要再犯了。