<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<router-link to="/user">用戶</router-link>
<router-link to="/article">文章</router-link>
<div class="content">
<router-view></router-view>
</div>
</div>
<script src="vue.js"></script>
<script src="vue-router.js"></script>
<script>
const User={
template:`<div>
<router-link to="/user/pass">修改密碼</router-link>
<router-link to="/user/info">用戶信息</router-link>
<router-view></router-view>
</div>`
}
const Article={
template:'<div>文章組件</div>'
}
const Pass={
template:'<div>修改密碼</div>'
}
const Info={
template:'<div>用戶信息</div>'
}
const router=new VueRouter({
routes:[
{
path:'/user',
component:User,
//配置子路由
children:[
{
path:'pass',
component:Pass
},
{
path:'info',
component:Info
}
]
},
{
path:'/article',
component:Article
}
]
})
new Vue({
el:"#app",
router
})
</script>
</body>
</html>
希望能幫助到你.
哪些地方寫的不好,不恰當的,給我留言!