使用vue-antDesign menu頁(yè)面方式(添加面包屑跳轉(zhuǎn))
使用vue-antDesign menu頁(yè)面(添加面包屑跳轉(zhuǎn))
看了很久文檔和其它人寫(xiě)的界面,我發(fā)現(xiàn)這個(gè)UI組件庫(kù)和element-ui的區(qū)別還是挺大的。
使用element-ui的時(shí)候,可以直接定義router 進(jìn)行綁定到路由,然后就可以顯示數(shù)據(jù)了,而且路由表的格式不需要特殊處理,隨便擺放都是可以的,只要使用的path或者name對(duì)應(yīng)的上就行
但是ant沒(méi)有指定路由的屬性,這使得我們?cè)谔D(zhuǎn)的時(shí)候需要使用到router-link 和router-view,這兩個(gè)才能正常顯示頁(yè)面
.vue文件
<template> <!-- 入口文件 --> <a-layout id="components-layout-demo-custom-trigger"> <a-layout-sider v-model="collapsed" :trigger="null" collapsible> <div class="logo" /> <a-menu theme="dark" mode="inline" :selectedKeys='selectedKeys' :default-selected-keys="[$route.path]" :inline-collapsed="collapsed" @select='selectMenuItem' > <template v-for='(item,index) in menuList'> <a-sub-menu :key="item.pageUrl" v-if='item.children.length > 0'> <span slot="title"><a-icon type="user" /><span>{{item.menuName}}</span></span> <a-menu-item v-for="(sun,ind) in item.children" :key="sun.pageUrl"> <router-link :to="item.pageUrl"> {{sun.menuName}} </router-link> </a-menu-item> </a-sub-menu> <a-menu-item :key="item.pageUrl" v-else> <router-link :to="item.pageUrl"> <a-icon type="video-camera" /> <span>{{item.menuName}}</span> </router-link> </a-menu-item> </template> </a-menu> </a-layout-sider> <a-layout> <a-layout-header style="background: #fff; padding: 0"> <a-icon class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="() => (collapsed = !collapsed)" /> </a-layout-header> <keep-alive> <a-layout-content :style="{ margin: '24px 16px', padding: '24px', background: '#fff', minHeight: '280px' }" > <!-- 面包屑 --> <a-breadcrumb :routes="routes" style="background-color: #f0f2f5; padding: 10px 0;" separator=">"> <template slot="itemRender" slot-scope="{ route, params, routes, paths }" > <span v-if="routes.length === 1"> {{ route.meta.title }} </span> <router-link v-else :to="`${route.path}`" > {{ route.meta.title }} </router-link> </template> </a-breadcrumb> <transition> <router-view/> </transition> </a-layout-content> </keep-alive> </a-layout> </a-layout> </template>
<script> export default { data() { return { collapsed: false, selectedKeys:['/admin'], menuList:[ { id:'0', menuName:'首頁(yè)', pageUrl:"/admin", title:"首頁(yè)", children:[] }, { id:'1', menuName:'文章管理', pageUrl:"/wzgl", title:"文章", children:[ { id:'1-1', menuName: "文章概覽", pageUrl:"/wzgl", title:"文章概覽", } ] }, { id:'2', menuName:'人員管理', pageUrl:"/rygl", title:"人員", children:[] }, { id:'3', menuName:'系統(tǒng)設(shè)置', pageUrl:"/xtgl", title:"系統(tǒng)", children:[] }, ], routes: [] }; }, created() { this.routes = this.$route.matched.filter(item => item.meta.title) //刷新頁(yè)面回到初始展開(kāi)頁(yè)面 // this.$router.push({ // path: this.selectedKeys[0] // }) }, methods:{ selectMenuItem(item,key){ this.$router.push({path: key}) } }, watch:{ // 監(jiān)聽(tīng)路由變化 $route(e){ this.routes = e.matched.filter(items => items.meta.title) this.selectedKeys=[e.path] } }, }; </script>
<style scoped="scoped"> #components-layout-demo-custom-trigger{ height: 100%; } #components-layout-demo-custom-trigger .trigger { font-size: 18px; line-height: 64px; padding: 0 24px; cursor: pointer; transition: color 0.3s; } #components-layout-demo-custom-trigger .trigger:hover { color: #1890ff; } #components-layout-demo-custom-trigger .logo { height: 32px; background: rgba(255, 255, 255, 0.2); margin: 16px; } </style>
路由表需要這個(gè)寫(xiě),在這里顯示的內(nèi)容全部都是當(dāng)前內(nèi)容的子元素,不然無(wú)法正常顯示,會(huì)直接給你跳轉(zhuǎn)到新界面.(因?yàn)槲抑笆褂胑lement-ui的時(shí)候是隨便放的路由位置,這一次就完全用不了,所以我就改了)
router.js
{ path: '/', name: 'admin', component: _import('pages/index'), children:[ { path: '/', redirect: { name: 'Home' }, }, { path:"/admin", name:"Home", component: _import('pages/home/index') }, { path:"/wzgl", name:"Article", component: _import('pages/article/article') }, { path:"/xtgl", name:"System", component: _import('pages/system/system') }, { path:"/rygl", name:"Munber", component: _import('pages/menber/users') }, ] }, //最后需要添加一句代碼,防止多次點(diǎn)擊的push的路由問(wèn)題 const routerPush = VueRouter.prototype.push VueRouter.prototype.push = function push(location) { return routerPush.call(this, location).catch(error=> error) }
在子路由中使用redirect ,是為了首次進(jìn)入的頁(yè)面的默認(rèn)選項(xiàng)問(wèn)題,不在頁(yè)面設(shè)置是為了刷新的時(shí)候,選擇的路徑不發(fā)生變化
新增面包屑
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- vue項(xiàng)目引入antDesignUI組件實(shí)現(xiàn)
- vue+antDesign實(shí)現(xiàn)樹(shù)形數(shù)據(jù)展示及勾選聯(lián)動(dòng)
- 基于vue3+antDesign2+echarts?實(shí)現(xiàn)雷達(dá)圖效果
- vue在antDesign框架或elementUI框架組件native事件中觸發(fā)2次問(wèn)題
- antdesign-vue結(jié)合sortablejs實(shí)現(xiàn)兩個(gè)table相互拖拽排序功能
- Vue中Table組件行內(nèi)右鍵菜單實(shí)現(xiàn)方法(基于 vue + AntDesign)
相關(guān)文章
Vue源碼解讀之Component組件注冊(cè)的實(shí)現(xiàn)
這篇文章主要介紹了Vue源碼解讀之Component組件注冊(cè)的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08詳解Vue Elementui中的Tag與頁(yè)面其它元素相互交互的兩三事
這篇文章主要介紹了詳解Vue Elementui中的Tag與頁(yè)面其它元素相互交互的兩三事,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09解決vue中el-date-picker?type=daterange日期不回顯的問(wèn)題
這篇文章主要介紹了解決vue中el-date-picker?type=daterange日期不回顯的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Vue 無(wú)限滾動(dòng)加載指令實(shí)現(xiàn)方法
這篇文章主要介紹了Vue 無(wú)限滾動(dòng)加載指令的實(shí)現(xiàn)代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-05-05Vue中判斷語(yǔ)句與循環(huán)語(yǔ)句基礎(chǔ)用法及v-if和v-for的注意事項(xiàng)詳解
在Vue指令中,最經(jīng)常被用于做邏輯操作的指令,下面這篇文章主要給大家介紹了關(guān)于Vue中判斷語(yǔ)句與循環(huán)語(yǔ)句基礎(chǔ)用法及v-if和v-for注意事項(xiàng)的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08專業(yè)級(jí)Vue?多級(jí)菜單設(shè)計(jì)
這篇文章主要為大家介紹了專業(yè)級(jí)的Vue?多級(jí)菜單設(shè)計(jì)實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07解決Vue運(yùn)算符報(bào)錯(cuò):Syntax Error: Unexpected token問(wèn)題
這篇文章主要介紹了解決Vue運(yùn)算符報(bào)錯(cuò):Syntax Error: Unexpected token問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01vue-router中的hash和history兩種模式的區(qū)別
大家都知道vue-router有兩種模式,hash模式和history模式,這里來(lái)談?wù)剉ue-router中的hash和history兩種模式的區(qū)別。感興趣的朋友一起看看吧2018-07-07vue實(shí)現(xiàn)長(zhǎng)圖垂直居上 vue實(shí)現(xiàn)短圖垂直居中
這篇文章主要為大家詳細(xì)介紹了vue彈性布局實(shí)現(xiàn)長(zhǎng)圖垂直居上,vue實(shí)現(xiàn)短圖垂直居中,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10