<style>
a{
text-decoration: none;
}
.router-link-active{
color: #ff1db5;
}
.adsd{
}
</style>
<body>
<div id="app">
<router-link to="/home">首页</router-link>
<router-link to="/user">用户页</router-link>
<!-- 盛放每个页面对应的内容-->
<router-view></router-view>
</div>
<script src="js/vue.js"></script>
<script src="js/vue-router.js"></script>
<script>
var Home ={
template:`
<h1>这是首页</h1>
`
};
var User ={
template:`
<div>
<h1>这是用户页</h1>
<ul>
<li>
<router-link to="/user/regist">注册</router-link>
</li>
<li>
<router-link to="/user/login">登录</router-link>
</li>
</ul>
<router-view></router-view>
</div>
`
};
var Regist = {
template:`
<h2>这是注册页</h2>3
`
};
var Login = {
template:`
<h2>这是登录页</h2>
`
};
const routes=[
{path:"/",component:Home},
{path:"/home",component:Home},
{path:"/user",component:User,
children:[
{path:"/user/regist",component:Regist},
{path:"/user/login",component:Login}
]
}
];
const route=new VueRouter({
routes:routes,
linkActiveClass:"adsd"
});
new Vue({
el:"#app",
router:route
});
</script>
</body>
结果如下: