使用vue-cli自动搭建的,组件里使用router-link报错,说router-link没有被注册,需要给组件再引入一次router,就不报错了,为什么呢? main.js内容如下,已经引入了router 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, template: ‘<App/>’, components: { App } })
router>index.js内容如下: import Vue from ‘vue’ import Router from ‘vue-router’ import HeaderTop from ‘@/components/header’ import Hello from ‘@/page/home/Hello’ import Firststep from ‘@/page/firststep/firststep’ import Secondstep from ‘@/page/secondstep/secondstep’ import Threestep from ‘@/page/threestep/threestep’ import Fourstep from ‘@/page/fourstep/fourstep’
Vue.use(Router)
export default new Router({ routes: [ { path: ‘/header’, name: ‘HeaderTop’, component: HeaderTop }, { path: ‘/’, name: ‘Hello’, component: Hello, children: [ { path: ‘/firststep’, name: ‘Firststep’, component: Firststep }, { path: ‘/secondstep’, name: ‘Secondstep’, component: Secondstep }, { path: ‘/threestep’, name: ‘Threestep’, component: Threestep }, { path: ‘/fourstep’, name: ‘Fourstep’, component: Fourstep } ] } ] })
使用router-link的组件如下: <template>
- <router-link :to="{ path: item.path }" >{{item.title}}</router-link>