命名视图

解读

有时候想同时 (同级) 展示多个视图,而不是嵌套展示,例如创建一个布局,有 sidebar (侧导航) 和 main (主内容) 两个视图,这个时候命名视图就派上用场了。你可以在界面中拥有多个单独命名的视图,而不是只有一个单独的出口。如果 router-view 没有设置名字,那么默认为 default。 不推荐使用

默认配置在主页面

const router = new VueRouter({
  routes: [
    {
      path: '/',
      components: {
        default: Foo,
        a: Bar,
        b: Baz
      }
    }
  ]
})
// 结构
<router-view class="view one"></router-view>
<router-view class="view two" name="a"></router-view>
<router-view class="view three" name="b"></router-view>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

配置在二级路由里

{
      path: "/shitumingming",
      component: Shitumingming,
      children: [
        {
          path: "",
          components: {
            default: ShituC,
            a: ShituA,
            b: ShituB
          }
        }
      ]
    }
    // 结构 shitumingming.vue
    <h1>在这里我将拥有多个视图面板</h1>
		<router-view class="view one"></router-view>
		<router-view class="view two" name="a"></router-view>
		<router-view class="view three" name="b"></router-view>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Last Updated:
Contributors: websong