先直观体验一把
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div id="app">yes <h2>Router Basic - 02</h2> <router-link to="{ path: '/home'}">Home</router-link> <router-link to="{ path: '/about'}">About</router-link> <router-view></router-view> </div> <template id="home"> <div> <h1>Home</h1> <p>{{msg}}</p> </div> <div> <ul class="nav nav-tabs"> <li> <a v-link="{ path: '/home/news'}">News</a> </li> <li> <a v-link="{ path: '/home/message'}">Messages</a> </li> </ul> <router-view></router-view> </div> </template> <template id="news"> <ul> <li>News 01</li> <li>News 02</li> <li>News 03</li> </ul> </template> <template id="message"> <ul> <li>Message 01</li> <li>Message 02</li> <li>Message 03</li> </ul> </template> <template id="about"> <div> <h1>About</h1> <p>This is the tutorial about vue-router.</p> </div> </template> </body> <script src="../vue.js"></script> <script src="../vue-router.js"></script> <script> const Home = { template: '#home', data: function () { return { msg: 'Hello, vue router!' } } }; var News = { template: '#news' }; var Message = { template: '#message' }; var About = { template: '#about' }; const router = new VueRouter({ routes: [ { path: '/', redirect: '/home',
},
{
path: '/home', component: Home,
children: [
{path: '/news', component: News},
{path: '/message', component: Message},
]
},
{
path: '/about', component: About
}
]
});
const app = new Vue({router}).$mount('#app')
</script>
</html>