I am new to vuejs and have some questions when using it. I create a root view, with 2 child component in it, the rootview.vue file looks like this:
<template>
<div id="rootView">
<calendar-top-view></calendar-top-view>
<calendar-bottom-view></calendar-bottom-view>
</div>
</template>
<script>
import calendarTopView from './calendarTopView.vue'
import calendarBottomView from './calendarBottomView.vue'
export default {
components: {
'calendar-top-view': calendarTopView,
'calendar-bottom-view': calendarBottomView
}
}
</script>
and in calendar-bottom-view component, I need to use vue-router to help switch between to child components: calendarView and agendaView. So I decide to add vue-router just in my calendar-bottom-vue component, and the code looks like below:
<template>
<div id='mainRightDiv'>
<div id='calendarToolboxDiv'>
<a v-link='{ path: "/calenarView"}'></a>
<a v-link='{ path: "/agendaView"}'></a>
</div>
<router-view></router-view>
</div>
</template>
<script type="text/javascript">
import Vue from 'vue'
import calendarView from './calendarView.vue'
import agendaView from './agendaView.vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
let App = Vue.extend({})
let router = new VueRouter()
router.map({
'/calendarView': {
component: calendarView
},
'/agendaView': {
component: agendaView
}
})
export default {
ready: function () {
router.go({ path: '/calendarView'})
}
}
</script>
What I intend to do is to let the router to render calendarView first when the component is initialized. But when I run this page, I got error message like
'router-view> can only be used inside a router-enabled app.'
I checked the official spec of vue-router and found in its demo code, vue-router was used in entry js of the demo app, not found any use in any child component.
So I wonder, how can I use vue-router in one of my child component, instead of root?