码迷,mamicode.com
首页 > 其他好文 > 详细

vue 路由 以及默认路由跳转

时间:2018-11-26 13:30:15      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:创建   com   模板   render   app   red   direct   dir   outer   

https://router.vuejs.org/


vue路由配置:


1.安装

npm install vue-router --save / cnpm install vue-router --save


2、引入并 Vue.use(VueRouter) (main.js)

import VueRouter from ‘vue-router‘

Vue.use(VueRouter)


3、配置路由

 

1、创建组件 引入组件


2、定义路由 (建议复制s)

const routes = [
{ path: ‘/foo‘, component: Foo },
{ path: ‘/bar‘, component: Bar },
{ path: ‘*‘, redirect: ‘/home‘ } /*默认跳转路由*/
]

3、实例化VueRouter

const router = new VueRouter({
routes // (缩写)相当于 routes: routes
})

4、挂载


new Vue({
el: ‘#app‘,
router,
render: h => h(App)
})



5 、根组件的模板里面放上这句话 <router-view></router-view>

 


6、路由跳转
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>

vue 路由 以及默认路由跳转

标签:创建   com   模板   render   app   red   direct   dir   outer   

原文地址:https://www.cnblogs.com/Spinoza/p/10019401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!