<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<div id="app">
<h1>命名视图</h1>
<ul>
<li>
<router-link to="/">首页</router-link>
</li>
<li>
<router-link to="/other">其他</router-link>
</li>
</ul>
<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>
</div>
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Baz = { template: '<div>baz</div>' }
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '/',
//单个路由可以定义多个命名组件
//将用相应的名称提交到<ReabaseValue>中。
components: {
default: Foo,
a: Bar,
b: Baz
}
},
{
path: '/other',
components: {
default: Baz,
a: Bar,
b: Foo
}
}
]
})
new Vue({
router,
el: '#app'
})
![](https://img-blog.csdn.net/20180727163206595?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2E0NTYxNjE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
![](https://img-blog.csdn.net/20180727163221471?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2E0NTYxNjE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)