Navigattion Bar by Vue.js2.0 + vue-router2.0
by bc_rikko
HTML
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-router/2.0.0/vue-router.min.js"></script>
<div id="app">
<nav>
<ul>
<router-link tag="li" to="/" exact><a>home</a></router-link>
<router-link tag="li" to="/foo"><a>foo</a></router-link>
<router-link tag="li" to="/bar"><a>bar</a></router-link>
</ul>
</nav>
<router-view></router-view>
</div>
CSS
nav {
background-color: #4fc08d;
}
ul > li {
display: inline-block;
margin: 0;
padding: 0;
width: 80px;
height: 40px;
line-height: 40px;
text-align: center;
}
ul > li > a {
display: block;
text-decoration: none;
color: #fff;
transition: all .3s ease-in-out;
}
.router-link-active > a,
ul > li > a:hover {
background-color: #fff;
color: #4fc08d;
}
JavaScript
// Components
const Home = { template: '<div>home</div>' }
const Foo = { template: '<div>foo</div>' };
const Bar = { template: '<div>bar</div>' };
// Router
const routes = [
{ path: '/', component: Home },
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
];
const router = new VueRouter({
routes
});
const app = new Vue({
router
}).$mount('#app');