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

vue 路由介绍

时间:2018-03-09 17:54:44      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   str   获取   去掉   渲染   one   his   apple   name   

1.带参数的路由

export default new Router({
  mode: ‘history‘, //去掉#
  routes: [
    {
      path: ‘/apple/:color‘,
      name: ‘Apple‘,
      component: Apple
    },
  ]
})
apple路由页面必须加上参数否则匹配不到页面,带引号的都是参数 :color
也可以是这样的 /apple/:color/detail/:type
通过this.$route.param 获取参数 参数为{color:red,type:animal}

2.嵌套路由 就是子路由

   在Apple组件下面加一个子组件Redapple

export default new Router({
  mode: ‘history‘, //去掉#
  routes: [
    {
      path: ‘/apple/:color‘,
      name: ‘Apple‘,
      component: Apple,
    children:[
      {
        path:‘/redapple‘,
        component:Redapple
      }
    ] }, ] })
Redapple组件就是Apple组件的子组件,
渲染到父组件中,所以在父组件添加<router-view/>

3.<router-link></router-link>

4.router.push()

 router

5.路由视图  路由map 路由导航

  命名路由和命名视图

6.重定向

export default new Router({
  mode: ‘history‘, //去掉#
  routes: [
  {
    path:‘/‘,
    redirect:‘/apple‘ //重定向 当访问根路由的时候 重定向到访问路由apple
  }, { path:
‘/apple/:color‘, name: ‘Apple‘, component: Apple, }, ] })

7.<keep-alive>

  <router-view/>

  </keep-alive>

切换过的组件被缓存起来,不再重新加载

vue 路由介绍

标签:style   str   获取   去掉   渲染   one   his   apple   name   

原文地址:https://www.cnblogs.com/Home-Yzz/p/8534705.html

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