1. 程式人生 > >vue2.0 路由知識一

vue2.0 路由知識一

應該 tag cnblogs hist com clas ons -s doctype

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="../vue2.2.js"></script>
        <script src="../vue-router2.1.js"></script>
    </head>
    <body>
        <div id="app"
> <p> <!--通過to屬性指定鏈接--> <!--<router-link>默認會被渲染成一個<a>標簽--> <router-link to="/home" tag="li">Home</router-link> <router-link to="/about">About</router-link> <
hr/> <!--<router-link :to="{path:‘home‘}">Home</router-link> <router-link :to="‘about‘" tag="li">About</router-link>--> </p> <!--路由出口,將路由匹配的組件渲染到這裏--> <!--將自動設置class屬性值 .router-link-active
--> <router-view></router-view> </div> <script> //1.定義組件 const Home = { template:"<div><h1>Home</h1><p>Hello,vue router!</p></div>" } const About = { template:"<div><h1>About</h1><p>這是關於vue-router</p></div>" } //2.定義路由 (每個路由應該映射一個組件) const routes = [{ path:"/home", component:Home },{ path:"/about", component:About },{ path:"/", redirect:"/home" /*component:Home*/ },{ path:"*", redirect:"/home"//重定向 } ] //3.創建router實例 ,然後傳‘routes’ 配置 const router = new VueRouter({ linkActiveClass:active, /*mode:"history",*/ routes // 相當於 routes:routes }) //4.創建和掛載根實例,從而讓整個應用都有路由功能 const vm = new Vue({ router //相當於 router:router }).$mount("#app") </script> </body> </html>

vue2.0 路由知識一