html制作一个导航页面包含vuejs路由
时间: 2024-06-01 16:13:58 浏览: 82
vue.js路由的简单创建
<!DOCTYPE html>
<html>
<head>
<title>Vue.js Navigation</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li v-for="route in routes" v-bind:class="{ active: route.path === $route.path }">
<router-link :to="route.path">{{ route.name }}</router-link>
</li>
</ul>
<router-view></router-view>
</div>
<script>
var Home = { template: '<div>Home</div>' }
var About = { template: '<div>About</div>' }
var Contact = { template: '<div>Contact</div>' }
var routes = [
{ path: '/', name: 'Home', component: Home },
{ path: '/about', name: 'About', component: About },
{ path: '/contact', name: 'Contact', component: Contact }
]
var router = new VueRouter({
routes: routes
})
var app = new Vue({
el: '#app',
router: router,
data: {
routes: routes
}
})
</script>
</body>
</html>
阅读全文