vue路由嵌套的SPA實現(xiàn)步驟
本文為大家分享了路由嵌套的SPA實現(xiàn)的步驟:
A(/a)組件需要嵌套B組件(/b)和C組件(/c)
①準(zhǔn)備嵌套其它組價的父組件 指定一個容器
在A組件指定一個容器
<router-view></router-ivew>
②在A組件的路由配置對象中指定children屬性
{
path:'/a',
component:A,
children:[
{path:'/b',component:B},
{path:'/c',component:C},
]
}
補充:
//數(shù)字如果超出記錄的次數(shù),是不行的。
this.$router.go(num);
如果num是正數(shù),向前進(jìn)
如果num是負(fù)數(shù),向后退
代碼
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>路由嵌套</title>
<script src="js/vue.js"></script>
<script src="js/vue-router.js"></script>
</head>
<body>
<div id="container">
<p>{{msg}}</p>
<router-view></router-view>
</div>
<script>
//登錄組件
var myLogin = Vue.component("login",{
template:`
<div>
<h1>登錄組件</h1>
<router-link to="/mail">登錄</router-link>
</div>
`
})
// 郵箱頁面
var myMail = Vue.component("mail",{
// 定義一個返回的方法
methods:{
goBack:function(){
this.$router.go(-1);
}
},
template:`
<div>
<h1>郵箱主頁面</h1>
<ul>
<li>
<router-link to="/inbox">收件箱</router-link>
</li>
<li>
<router-link to="/outbox">發(fā)件箱</router-link>
</li>
</ul>
// 點擊按鈕返回前面的頁面
<button @click="goBack">返回</button>
<router-view></router-view>
</div>
`
// 指定一個容器,加載收件箱或收件箱的列表
})
// 收件箱組件
var myInBox = Vue.component("inbox-component",{
template:`
<div>
<h4>收件箱</h4>
<ul>
<li>未讀郵件1</li>
<li>未讀郵件2</li>
<li>未讀郵件3</li>
</ul>
</div>
`
})
// 發(fā)件箱組件
var myOutBox = Vue.component("outbox-component",{
template:`
<div>
<h4>發(fā)件箱</h4>
<ul>
<li>已發(fā)送郵件1</li>
<li>已發(fā)送郵件2</li>
<li>已發(fā)送郵件3</li>
</ul>
</div>
`
})
//配置路由詞典
new Vue({
router:new VueRouter({
routes:[
{path:'',redirect:'/login'},
{path:'/login',component:myLogin},
{path:'/mail',component:myMail,children:[
{path:'/inbox',component:myInBox},
{path:'/outbox',component:myOutBox}
]},
]
}),
el:"#container",
data:{
msg:"Hello VueJs"
}
})
//通過再次指定一個<router-view></router-view>和children:[]
</script>
</body>
</html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue嵌套路由與404重定向?qū)崿F(xiàn)方法分析
- vue router嵌套路由在history模式下刷新無法渲染頁面問題的解決方法
- vue router學(xué)習(xí)之動態(tài)路由和嵌套路由詳解
- vue動態(tài)路由實現(xiàn)多級嵌套面包屑的思路與方法
- Vue實現(xiàn)路由跳轉(zhuǎn)和嵌套
- vue router路由嵌套不顯示問題的解決方法
- 詳解vue嵌套路由-params傳遞參數(shù)
- 詳解vue嵌套路由-query傳遞參數(shù)
- VUE多層路由嵌套實現(xiàn)代碼
- vue 2.0路由之路由嵌套示例詳解
- vue2.0嵌套路由實現(xiàn)豆瓣電影分頁功能(附demo)
- vue-router:嵌套路由的使用方法
- Vue三層嵌套路由的示例代碼
相關(guān)文章
Vue.extend 登錄注冊模態(tài)框的實現(xiàn)
這篇文章主要介紹了Vue.extend 登錄注冊模態(tài)框的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
vue3?使用defineAsyncComponent與component標(biāo)簽實現(xiàn)動態(tài)渲染組件思路詳解
這篇文章主要介紹了vue3?使用defineAsyncComponent與component標(biāo)簽實現(xiàn)動態(tài)渲染組件,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03
Vue3中如何修改父組件傳遞到子組件中的值(全網(wǎng)少有!)
大家都知道,vue是具有單向數(shù)據(jù)流的傳遞特性,下面這篇文章主要給大家介紹了關(guān)于Vue3中如何修改父組件傳遞到子組件中值的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
關(guān)于Elementui中toggleRowSelection()方法實現(xiàn)分頁切換時記錄之前選中的狀態(tài)
這篇文章主要介紹了關(guān)于Elementui中toggleRowSelection()方法實現(xiàn)分頁切換時記錄之前選中的狀態(tài),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03

