網(wǎng)站首頁 編程語言 正文
局部路由守衛(wèi)component守衛(wèi)
component守衛(wèi)(beforeRouteEnter、beforeRouteLeave)
- 代碼位置:在路由組件中,代碼是寫在component當(dāng)中的(XXX.vue)
- beforeRouteEnter、beforeRouteLeave都有三個(gè)參數(shù):
- to參數(shù):to是一個(gè)路由對(duì)象,表示到哪兒去(跳轉(zhuǎn)的下一個(gè)路由組件)。
- from參數(shù):form是一個(gè)路由對(duì)象,表示從哪來(從哪個(gè)路由切換過來的)。
- next參數(shù):next是一個(gè)函數(shù),表示允許通過,可以繼續(xù)向下走。
- beforeRouteEnter格式:
beforeRouteEnter(to, from, next){}
- beforeRouteLeave格式:
beforeRouteLeave(to, from, next){}
- 執(zhí)行時(shí)機(jī):
- beforeRouteEnter的執(zhí)行時(shí)機(jī):進(jìn)入路由組件之前執(zhí)行
- beforeRouteLeave的執(zhí)行時(shí)機(jī):離開路由組件之前執(zhí)行
- 兩個(gè)函數(shù)都是執(zhí)行一個(gè)對(duì)象
- 全局前置、后置路由守衛(wèi) 和 component守衛(wèi)的區(qū)別
- 全局前置、后置路由守衛(wèi)在調(diào)用時(shí)兩個(gè)都會(huì)啟動(dòng)
- beforeRouteEnter、beforeRouteLeave在調(diào)用時(shí)只能有一個(gè)能用,另一個(gè)就不能用
// City.vue
<template>
<div>
<h2>區(qū)</h2>
<ul>
<li>{{a1}}</li>
<li>{{a2}}</li>
<li>{{a3}}</li>
</ul>
</div>
</template>
<script>
export default {
name : 'City',
props : ['a1', 'a2', 'a3'],
beforeRouteEnter(to, from, next){
console.log(`進(jìn)入到路由組件之前:${to.meta.title}`);
next()
},
beforeRouteLeave(to, from, next){
console.log(`離開路由組件之前:${from.meta.title}`);
next()
}
}
</script>
// HuBei.vue
<template>
<div>
<h2>市</h2>
<div>
<ul>
<li>
<router-link :to="{
name : 'wh',
params : {
a1 : wh[0],
a2 : wh[1],
a3 : wh[2],
}
}">
武漢市
</router-link>
</li>
<li>
<router-link :to="{
name : 'hs',
params : {
a1 : hs[0],
a2 : hs[1],
a3 : hs[2],
}
}">
黃石市
</router-link>
</li>
</ul>
<router-view></router-view>
</div>
</div>
</template>
<script>
export default {
name : 'HuBei',
data(){
return{
wh : ['江岸區(qū)', '江漢區(qū)', '橋口區(qū)'],
hs : ['下陸區(qū)', '鐵山區(qū)', '西塞山區(qū)']
}
}
}
</script>
// App.vue
<template>
<div>
<h2>省</h2>
<div>
<ul>
<li><router-link to="/hubei">湖北省</router-link></li>
</ul>
<router-view></router-view>
</div>
</div>
</template>
<script>
export default {
name : 'App'
}
</script>
// index.js
import VueRouter from 'vue-router'
import HuBei from '../pages/HuBei'
import City from '../pages/City'
const router = new VueRouter({
routes : [
{
name : 'bei',
path : '/hubei',
component : HuBei,
meta : {title : '湖北省'},
children : [
{
name : 'wh',
path : 'wuhan',
component : City,
props : true,
meta : {
isAuth : true,
title : '武漢市'
},
},
{
name : 'hs',
path : 'huangshi',
component : City,
props : true,
meta : {
isAuth : true,
title : '黃石市'
}
}
]
}
]
})
export default router
原文鏈接:https://blog.csdn.net/weixin_47957908/article/details/134346232
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-09-12 docker?清理緩存腳本解析_docker
- 2023-01-27 Python異常與錯(cuò)誤處理詳細(xì)講解_python
- 2022-03-20 Android自動(dòng)攔截與接聽功能APK黑白名單_Android
- 2022-09-03 Python?pandas找出、刪除重復(fù)的數(shù)據(jù)實(shí)例_python
- 2022-03-15 React?Router?V6更新內(nèi)容詳解_React
- 2022-07-16 windows下 使用 nvm-windows 管理node版本
- 2022-11-26 詳解Python中的with語句和上下文管理器_python
- 2022-04-21 R語言繪制數(shù)據(jù)可視化Dumbbell?plot啞鈴圖_R語言
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支