Vue2.0路由学习探索总结---get-started
先直观体验一把
<!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 class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="../vue.js"></script> <script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="../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>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦