1. 程式人生 > >vue的路由

vue的路由

一個 指定 charset lin component mount one pan out

先寫個基礎版

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
    <h1>Hello App!</h1>
    <p>
        <!-- 使用 router-link 組件來導航. -->
        <!-- 通過傳入 `to` 屬性指定鏈接. -->
        <!-- <router-link> 默認會被渲染成一個 `<a>` 標簽 -->

        <router-link to="/foo">go to foo</router-link>
        <router-link to="/Bar">go to bar</router-link>


    </p>
    <!-- 路由出口 -->
    <!-- 路由匹配到的組件將渲染在這裏 -->
    <router-view></router-view>
</div>


<script>

    var
Foo ={template:"<div>foo</div>"} var Bar ={template:‘<p>bar</p>‘} var routes=[ { path:‘/foo‘, component:Foo }, { path:‘/bar‘, component:Bar } ]; var router = new VueRouter({ routes });
var app = new Vue({ router }).$mount("#app"); </script> </body> </html>

vue的路由