<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
padding: 0px;
margin: 0px;
}
.router-link-active{
color:red;
}
li{
list-style: none;
float: left;
padding-left: 50px;
}
</style>
</head>
<body>
<div id='app'>
<!--//1.-->
<router-link to='/home'>首頁(yè)</router-link>
<router-link to='/detail'>詳情頁(yè)</router-link>
<router-link to='/wang'>王諾嵐</router-link>
<!-- 盛放每個(gè)頁(yè)面對(duì)應(yīng)的內(nèi)容-->
<router-view></router-view>
</div>
<script src='js/vue.js'></script>
<script src='js/vue-router.js'></script>
<script>
//2.創(chuàng)建組件
var Home={
template:`
<h1>楊夢(mèng)嬌</h1>
`
}
var Detail={
template:`
<div>
<h1>小摳逼</h1>
<ul>
<li>
<router-link to='/detail/zhuce'>注冊(cè)</router-link>
</li>
<li>
<router-link to='/detail/denglu'>登錄</router-link>
</li>
</ul>
<router-view></router-view>
</div>
`
}
var Zhuce={
template:`
<h4>這是注冊(cè)頁(yè)面</h4>
`
}
var Denglu={
template:`
<h4>這是登錄頁(yè)面</h4>
`
}
var Wang={
template:`
<div>
<ul>
<li>楊夢(mèng)嬌是傻逼</li>
<li>楊夢(mèng)嬌是小摳逼</li>
<li>楊夢(mèng)嬌小氣鬼</li>
<li>楊夢(mèng)嬌小黑子</li>
<li>楊夢(mèng)嬌單身狗</li>
<li>楊夢(mèng)嬌是傻逼</li>
<li>楊夢(mèng)嬌是小摳逼</li>
<li>楊夢(mèng)嬌小氣鬼</li>
<li>楊夢(mèng)嬌小黑子</li>
<li>楊夢(mèng)嬌單身狗</li>
</ul>
</div>
`
}
//3.配置路由
const routes=[
{path:'/',component:Home},
{path:'/home',component:Home},
{
path:'/detail',
component:Detail,
children:[
{path:'zhuce',component:Zhuce},
{path:'denglu',component:Denglu},
]
},
{path:'/wang',component:Wang}
]
//4.創(chuàng)建一個(gè)路由實(shí)例
const router=new VueRouter({
routes:routes
})
//把路由掛在到vue實(shí)例上
new Vue({
el:'#app',
router:router
})
</script>
</body>
</html>
路由(嵌套)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 子路由配置:在父級(jí)路由中添加children屬性,值為子路由配置當(dāng)想讓某個(gè)子路由作為默認(rèn)項(xiàng)時(shí),path的值為空字符...
- 參考實(shí)例代碼:http://jsfiddle.net/yyx990803/L7hscd8h/ http://js...
- 1.簡(jiǎn)單實(shí)例 vue的核心插件,可創(chuàng)建單頁(yè)面應(yīng)用又叫SPA(SIWGLE PAGE APPLICATIDN)應(yīng)用V...