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

使用vue-antDesign menu頁(yè)面方式(添加面包屑跳轉(zhuǎn))

 更新時(shí)間:2024年01月03日 15:04:28   作者:hjy170314  
這篇文章主要介紹了使用vue-antDesign menu頁(yè)面方式(添加面包屑跳轉(zhuǎn)),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

使用vue-antDesign menu頁(yè)面(添加面包屑跳轉(zhuǎn))

最終效果1

最終效果2

看了很久文檔和其它人寫(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è)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論