Ant Design Vue 4.0 a-modal弹窗组件封装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| <template> <a-layout-sider class="menu-main"> <div class="logo">Han</div> <a-menu v-model:selectedKeys="routerPathKey" theme="light" mode="inline" @click="onTitleClick" :openKeys="ACTIVE_NAV" > <template v-for="itm in NAV_MENU" :key="itm.name"> <a-sub-menu v-if="itm.children && itm.children.length > 0" :key="itm.name" > <template #title> <icon-font :type="(itm.meta?.icon as any)" /> <span>{{ itm.name }}</span> </template> <a-menu-item v-for="_itm in itm.children" :key="_itm.name"> <icon-font :type="(_itm.meta?.icon as any)" /> <span>{{ _itm.name }}</span> </a-menu-item> </a-sub-menu> <a-menu-item v-if="!itm.children || itm.children.length < 1" :key="itm.name" > <icon-font :type="(itm.meta?.icon as any)" /> <span>{{ itm.name }}</span> </a-menu-item> </template> <a-menu-item key="敬请期待" disabled> <icon-font type="han-icon-jingqingqidai1" /> <span>敬请期待</span> </a-menu-item> </a-menu> </a-layout-sider> </template> <script lang="ts" setup> import { ref } from "vue"; import { useRouter } from "vue-router"; const router = useRouter();
import { createFromIconfontCN } from "@ant-design/icons-vue"; const IconFont = createFromIconfontCN({ scriptUrl: "/icon/nav-icon/iconfont.js", }); const NAV_MENU = router.options.routes[0].children; const onTitleClick = (res: any) => { router.push({ name: res.key }); }; const routerPathKey = ref<Array<any>>([]); const ACTIVE_NAV = ref<string[]>([]); const initFN = () => { ACTIVE_NAV.value = []; routerPathKey.value = [router.currentRoute.value.name]; NAV_MENU?.forEach((itm: any) => { itm.children?.find((item: { name: string }) => { return ( item.name == routerPathKey.value[0] && ACTIVE_NAV.value.push(itm.name) ); }); }); }; initFN(); router.afterEach((to, from) => { initFN(); }); </script> <style lang="less" scoped> @import "index.less"; </style>
|