Vue--router-->>項目多路由嵌套--常用

來源:互聯網
上載者:User
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>vue-router</title>    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css">    <script src="js/vue.js" ></script>    <!--- 第一步,將vue-router的原始碼引入--->    <script src="js/vue-router.js" ></script></head><body><div id="app">    <div class="container">        <ul class="nav nav-pills">            <!--- 使用router-link 進行跳轉 --->            <li><router-link to="/index/i">首頁</router-link></li>            <li><router-link to="/index/b">圖書列表</router-link></li>            <li><router-link to="/index/g">遊戲列表</router-link></li>        </ul>        <div>            <router-view></router-view>        </div>    </div></div><script>    /**     * 配置路由,使用官方的VueRouter     * new VueRouter 得到一個VueRouter的執行個體     * 在VueRouter中傳遞參數(對象)     * 在參數中有個routes的數組屬性     * 這個數組是一個對象數組     * 每一個對象就是一個路由狀態     */    var router = new VueRouter({        routes : [            {                path : "/index",                component : {                    template : `//這裡用了反(單引號)可以有代碼提醒 也可以用正常的單引號                            <div>                                <h1>首頁</h1>                                <router-view></router-view>                            </div>                        `//                        template : "<div><router-view></router-view></div>"  另外一種寫法                },                children : [                    {                        path : "i",                        component : {                            template : "<h1>這個是嵌套的首頁</h1>"                        }                    },                    {                        path : "b",                        component : {                            template : "<h1>這個是嵌套的圖書列表</h1>"                        }                    },                    {                        path : "g",                        component : {                            template : "<h1>這個是嵌套的遊戲列表</h1>"                        }                    }                ]            }        ]    });    new Vue({        data : {            username : "劉德華"        },        router : router    }).$mount("#app");</script></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.