vue-路由基础

2019-12-07  本文已影响0人  幻影翔

a.动态路由

 {
   // 动态路由
  path: '/argu/:name',
  component: () => import('@/views/argu.vue')
}
// argu.vue
<template>
  <div>
      hello {{ $route.params.name }}
  </div>
</template>   

b.嵌套路由

{
    // 嵌套路由
    path:   '/parent',
    component: () => import('@/views/parent.vue'),
    children: [
        {
            path: 'child',
            component: () => import('@/views/child.vue')
        }
    ]
},

// parent.vue
<template>
  <div>
        I am parent
        <router-view :to="{name: 'child'}"/>
  </div>
</template>

c.命名路由

 <router-view name="email"/>

d. 命名视图
注意是使用components

{
    path: '/name_view',
    components: {
        default: () => import('@/views/Home.vue'),
        email: () => import('@/views/email.vue'),
        tel: () => import('@/views/tel.vue')
    }
}
//使用
<template>
   <div id="app">
      <div id="nav">
        <router-link :to="{name: 'home'}">Home</router-link> |
        <router-link v-bind:to="{name: 'about'}">About</router-link>
      </div>
      <router-view />  //这个不能少
      <router-view name="email"/>
      <router-view name="tel"/>
  </div>
</template>
上一篇下一篇

猜你喜欢

热点阅读