vue-router精简demo
- cnpm install vue-router --save-dev 或者 cnpm install vue-router --save
- 全局引用VueRouter
import VueRouter from 'vue-router'
Vue.use(VueRouter);
- const router对象
const router = new VueRouter({
mode: 'history',
base: __dirname,
routes: [
{path: '/y1', component: y1},
{path: '/y2', component: y2},
]
})
- 在实例中使用
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
- 具体页面写法
<router-link to="/y1">去页面1</router-link>
<router-link to="/y2">去页面2</router-link>
<router-view></router-view>