Ant Design的layout布局 --- 根据路由配置渲染

<template>
  <a-layout>
    <a-layout>
      <a-layout-sider width="200" style="background: #fff">
        <a-menu mode="inline"
          :style="{ height: '100%', borderRight: 0 }">
          <template v-for="item in routes" :key="item.path" 
          :selectedKeys="selectedKeys"
           :openKeys="openKeys"
            >
            <template v-if="item.children && item.children.length">
            <a-sub-menu>
              <template #title>
                
                <router-link :to="item.path" :key="item.path">
                  <span>{{ item.meta.title }} </span>
                </router-link>
              </template>
              <template v-if="item.children && item.children.length">
                <a-menu-item v-for="child in item.children" :key="child.path">
                  <span>{{ child.meta.title }}</span>
                  <router-link :key="child.path" :to="item.path + '/' + child.path">
                  </router-link>
                </a-menu-item>
              </template>
            </a-sub-menu>
          </template>
          <template v-else>
            <a-menu-item :key="item.path">
                  <span>{{ item.meta.title }}</span>
                  <router-link :key="item.path" :to="item.path">

                  </router-link>
                </a-menu-item>
          </template>
        </template>
        </a-menu>
      </a-layout-sider>
      <a-layout style="padding: 0 24px 24px">
        <a-breadcrumb style="margin: 16px 0">
          <a-breadcrumb-item>Home</a-breadcrumb-item>
          <a-breadcrumb-item>List</a-breadcrumb-item>
          <a-breadcrumb-item>App</a-breadcrumb-item>
        </a-breadcrumb>
        <a-layout-content :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }">
          <router-view></router-view>
        </a-layout-content>
      </a-layout>
    </a-layout>
  </a-layout>
</template>
<script lang="ts" setup>
import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons-vue';
import { defineComponent, reactive, ref , onMounted} from 'vue';
import { routes } from './router'
import { useRoute } from 'vue-router'
const route = useRoute()
let selectedKeys = ref(['0']);
let collapsed = ref<boolean>(false);
</script>
<style>
#components-layout-demo-top-side-2 .logo {
  float: left;
  width: 120px;
  height: 31px;
  margin: 16px 24px 16px 0;
  background: rgba(255, 255, 255, 0.3);
}

.ant-row-rtl #components-layout-demo-top-side-2 .logo {
  float: right;
  margin: 16px 0 16px 24px;
}

.site-layout-background {
  background: #fff;
}
</style>
  

路由配置

import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import index from '@/index.vue'
import websiteUsage from '@/components/contentList/usage/websiteUsage.vue'
import galleryUsage from '@/components/contentList/usage/galleryUsage.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    component: index,
    meta:{
      title:'首页'
    }
  },
  {
    path: '/usageProcess',
    name: 'galleryUsage',
    component: index,
    meta:{
      title:'使用流程'
    },
    children:[
      {
        path: 'websiteUsage',
    name: 'websiteUsage',
    component: websiteUsage,
    meta:{
      title:'网站使用流程'
    }
  },
  {
    path: 'galleryUsage',
name: 'galleryUsage',
component: galleryUsage,
meta:{
  title:'创建图库流程'
}
}
    ]
  },
  {
    path: '/userManagement',
    name: 'userManagement',
    component: index,
    meta:{
      title:'用户管理'
    }
  },
  {
    path: '/gallery',
    name: 'gallery',
    component: index,
    meta:{
      title:'创建图库'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
export { routes }
export default router

效果图

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值