2017-06-30 89 views

回答

1

這裏有一個裸露的骨頭例子,以幫助準備:

<html> 
<head> 
    <script src="https://unpkg.com/vue"></script> 
    <script src="https://unpkg.com/[email protected]/dist/vue-router.js"></script> 
</head> 
<body> 
<div id="app"> 
    <p><router-link to="/page1">Go to Page 1</router-link></p> 
    <p><router-link to="/page2">Go to Page 2</router-link></p> 
    <p><router-view></router-view></p> 
</div> 

<script> 
    var PageTwoComponent = Vue.component('comp2',{ 
     template: '<p>Component Two</p>' 
    }) 
    var PageOneComponent = Vue.component('comp1',{ 
     template: '<p>Component One</p>' 
    }) 

    const routes = [ 
     {path: '/page1', component: PageTwoComponent}, 
     {path: '/page2', component: PageOneComponent} 
    ] 

    const router = new VueRouter({ 
     routes 
    }) 

    var app = new Vue({ 
     router 
    }).$mount('#app') 

</script> 
</body> 
</html> 
+0

謝謝@MarkM。那幫助 –