继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Vue2.0路由学习探索总结---命名视图

resharpe
关注TA
已关注
手记 102
粉丝 7244
获赞 3476
Vue2.0路由学习探索总结---命名视图
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../vue.js"></script>
    <script src="../vue-router.js"></script>
    <style>
        .router-link-active {
            color: red
        }
    </style>
</head>
<body>
<div id="app">
    <h1>Named Views</h1>
    <ul>
        <li>
            <router-link to="/">/</router-link>
        </li>
        <li>
            <router-link to="/other">/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>
</body>
<script>
    const Foo = {template: '<div>foo</div>'}
    const Bar = {template: '<a>bar</a>'}
    const Baz = {template: '<h1>baz</h1>'}
   const router = new VueRouter({
        mode: 'history',
        routes: [
            {
                path: '/',
               components: {
                    default: Foo,
                    a: Bar,
                    b: Baz
                }
            },
            {
                path: '/other',
                components: {
                    default: Baz,
                    a: Bar,
                    b: Foo
                }
            }
        ]
    });

    //    new Vue({
    //        router,
    //        el: '#app'
    //    });
    const app = new Vue({
        router
    }).$mount('#app')

</script>
</html>
打开App,阅读手记
3人推荐
发表评论
随时随地看视频慕课网APP