欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue的路由動(dòng)畫(huà)切換頁(yè)面無(wú)法讀取meta值的bug記錄

 更新時(shí)間:2023年05月16日 14:33:39   作者:Amelia Pond  
這篇文章主要介紹了vue的路由動(dòng)畫(huà)切換頁(yè)面無(wú)法讀取meta值的bug記錄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue路由動(dòng)畫(huà)切換頁(yè)面無(wú)法讀取meta值的bug

在vue項(xiàng)目的二級(jí)路由中,想要通過(guò)設(shè)置路由表中的meta值,來(lái)判斷頁(yè)面的slide-left 和slide-right的方向。

對(duì)于從左到右的排列,給routes依次設(shè)為1,2,3,4…的值,使其可以通過(guò)大小來(lái)判斷from和to,并顯示出不同的劃入 / 劃出效果

{
?? ?path: 'aaa',
?? ?name: 'aaa',
?? ?component: aaa,
?? ?meta:1
},
{
?? ?path: 'bbb',
?? ?name: 'bbb',
?? ?component: bbb,
?? ?redirect:'bbb/baba',
?? ?meta:2,
?? ?children: [
?? ?{
?? ??? ?path: 'baba',
?? ??? ?name: 'baba',
?? ??? ?component: baba
?? ?}, {
?? ??? ?path: 'ccc',
?? ??? ?name: 'ccc',
?? ??? ?component: ccc
?? ?}, {
?? ??? ?path: 'ddd',
?? ??? ?name: 'ddd',
?? ??? ?component: ddd
?? ?}, {
?? ??? ?path: 'eee',
?? ??? ?name: 'eee',
?? ??? ?component: eee
?? ?}, {
?? ??? ?path: 'fff',
?? ??? ?name: 'fff',
?? ??? ?component: fff
?? ?}],
},
{
?? ?path: 'ggg',
?? ?name: 'ggg',
?? ?meta:4,
?? ?component: ggg
},
{
?? ?path: 'hhh',
?? ?name: 'hhh',
?? ?meta:3,
?? ?component: hhh
},

然鵝,

在設(shè)置的過(guò)程中,其中一個(gè)路由始終無(wú)法讀到all這個(gè)路由中的meta:2

導(dǎo)致切換路由的動(dòng)畫(huà)效果出了問(wèn)題

問(wèn)題原因

讀不到的meta的是因?yàn)樵O(shè)置了子路由以及重定向。

解決方法

把meta值加在它的子路由上,

{
?? ?path: 'bbb',
?? ?name: 'bbb',
?? ?component: bbb,
?? ?redirect:'bbb/baba',
?? ?//meta:2,
?? ?children: [
?? ?{
?? ??? ?path: 'baba',
?? ??? ?name: 'baba',
?? ??? ?component: baba,
?? ??? ?meta:2
?? ?}, {
?? ??? ?path: 'ccc',
?? ??? ?name: 'ccc',
?? ??? ?component: ccc
?? ?}, {
?? ??? ?path: 'ddd',
?? ??? ?name: 'ddd',
?? ??? ?component: ddd
?? ?}, {
?? ??? ?path: 'eee',
?? ??? ?name: 'eee',
?? ??? ?component: eee
?? ?}, {
?? ??? ?path: 'fff',
?? ??? ?name: 'fff',
?? ??? ?component: fff
?? ?}],
},

vue路由元信息meta

路由元信息

定義路由的時(shí)候可以配置meta字段。

那么我們可以利用meta字段來(lái)做什么呢?

設(shè)置title

? ? name: 'category',
? ? component: () => import('./view/creatBrainStorm/creat/category'),
? ? meta: {
? ? ? title: '卓腦'
? ? }

我們可以在鉤子函數(shù)router.beforeEach中獲取meta中的title數(shù)據(jù),并設(shè)置為頁(yè)面標(biāo)題。

router.beforeEach((to, from, next) => {
? const title = to.meta && to.meta.title
? if (title) {
? ? document.title = title
? }
}

權(quán)限校驗(yàn)(例:登錄校驗(yàn))

{
? ? name: 'cart',
? ? component: () => import('./view/cart'),
? ? meta: {
? ? ? title: '購(gòu)物車(chē)',
? ? ? requireAuth: true // 當(dāng)有這個(gè)字段的時(shí)候,我們就認(rèn)為這個(gè)路由頁(yè)面是要有登錄權(quán)限的
? ? }
? }

檢查meta中元字段:

if (to.meta.requireAuth) {
? ? // 不直接通過(guò)本地緩存進(jìn)行判斷,而是通過(guò)Vuex的屬性狀態(tài)進(jìn)行判斷
? ? if (store.state.user.token) {
? ? ? next()
? ? } else {
? ? ? next({
? ? ? ? path: '/login',
? ? ? ? query: { redirect: to.fullPath }
? ? ? })
? ? }
? } else {
? ? next()
? }

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論