Vue报错[Vue warn]: Unknown custom element: router-view

配置如下:
App.vue:

<template>
  <div id="app">
    <router-view />
  div>
template>

main.js:

import Vue from 'vue'
import App from './App.vue'
import router from './router.js'
Vue.config.productionTip = false
new Vue({
  router,
  render: h => h(App),
  
}).$mount('#app')

router.js:

import Router from 'vue-router'

export default new Router({
    mode: 'history',
    routes: [
      //下载页
      {
        path: '/aa',
        name: 'HelloWorld',
        component: () =>
          import(/* webpackChunkName: "download" */ './components/HelloWorld.vue')
      }
    ]
  })

错误内容:

[Vue warn]: Unknown custom element: <router-view> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

---> <App> at src/App.vue

问题原因:

vue-router没有引入

问题解决:修改router.js

import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
    mode: 'history',
    routes: [
      //下载页
      {
        path: '/aa',
        name: 'HelloWorld',
        component: () =>
          import(/* webpackChunkName: "download" */ './components/HelloWorld.vue')
      }
    ]
  })

问题解决。

你可能感兴趣的:(Vue)