vue 路由meta 設(shè)置導航隱藏與顯示功能的示例代碼
vue 路由meta 設(shè)置title 導航隱藏,具體代碼如下所示:
router.js
routes: [{ path: '/', name: 'HelloWorld', component: HelloWorld, meta: { title: "HelloWorld", 要現(xiàn)實的title show: true 設(shè)置導航隱藏顯示 } }]
App.vue
<template> <div id="app"> <router-view></router-view> <bottom v-show="this.$route.meta.show"></bottom> this.$route.meta.show 顯示或隱藏 </div> </template>
main.js
router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } next() })<br><br>監(jiān)聽路由 寫入 title
PS:vue 中路由meta
meta字段(元數(shù)據(jù))
直接在路由配置的時候,給每個路由添加一個自定義的meta對象,在meta對象中可以設(shè)置一些狀態(tài),來進行一些操作。用它來做登錄校驗再合適不過了
{ path: '/actile', name: 'Actile', component: Actile, meta: { login_require: false }, }, { path: '/goodslist', name: 'goodslist', component: Goodslist, meta: { login_require: true }, children:[ { path: 'online', component: GoodslistOnline } ] }
這里我們只需要判斷item下面的meta對象中的login_require是不是true,就可以做一些限制了
router.beforeEach((to, from, next) => { if (to.matched.some(function (item) { return item.meta.login_require })) { next('/login') } else next() })
總結(jié)
到此這篇關(guān)于vue 路由meta 設(shè)置導航隱藏與顯示功能的示例代碼的文章就介紹到這了,更多相關(guān)vue 路由meta 設(shè)置導航隱藏與顯示內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
關(guān)于vue設(shè)置環(huán)境變量全流程
這篇文章主要介紹了關(guān)于vue設(shè)置環(huán)境變量全流程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03vue+ElementUI實現(xiàn)訂單頁動態(tài)添加產(chǎn)品數(shù)據(jù)效果實例代碼
本篇文章主要介紹了vue+ElementUI實現(xiàn)訂單頁動態(tài)添加產(chǎn)品效果實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07antd form表單使用setFildesValue 賦值失效的解決
這篇文章主要介紹了antd form表單使用setFildesValue 賦值失效的解決方案,具有很好的參考價值,希望對大家有所幫助。2023-04-04sortable+element 實現(xiàn)表格行拖拽的方法示例
這篇文章主要介紹了sortable+element 實現(xiàn)表格行拖拽的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-06-06使用vue.js2.0 + ElementUI開發(fā)后臺管理系統(tǒng)詳細教程(二)
這篇文章主要介紹了使用vue.js2.0 + ElementUI開發(fā)后臺管理系統(tǒng)詳細教程(二),非常不錯,具有參考借鑒價值,需要的朋友參考下吧2017-01-01