From 9a1025de4b74e0a1144184674a75e79afcdb7034 Mon Sep 17 00:00:00 2001 From: azhe <799552341@qq.com> Date: Tue, 18 Jul 2023 15:26:19 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(menu-item):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?API:=20routerLink=EF=BC=8C=E5=8F=AF=E6=8C=87=E5=AE=9A=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E9=A1=B9=E6=B8=B2=E6=9F=93=E4=B8=BARouter=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E8=B7=B3=E8=BD=AC=E7=9A=84a=E6=A0=87=E7=AD=BE=20(#256?= =?UTF-8?q?5)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 81cdd6004337c1e65d71ef81fd7b0985f5fb1246. --- src/menu/menu-item-props.ts | 6 +----- src/menu/menu-item.tsx | 28 +++++----------------------- src/menu/type.ts | 6 +----- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/menu/menu-item-props.ts b/src/menu/menu-item-props.ts index 3cf780dc5..4babf9de9 100644 --- a/src/menu/menu-item-props.ts +++ b/src/menu/menu-item-props.ts @@ -18,7 +18,7 @@ export default { }, /** 是否禁用菜单项展开/收起/跳转等功能 */ disabled: Boolean, - /** 跳转链接,菜单项渲染为a标签,当routerLink为true时将使用Router进行路由跳转 */ + /** 跳转链接 */ href: { type: String, default: '', @@ -33,10 +33,6 @@ export default { router: { type: Object as PropType, }, - /** - * 菜单项内容是否渲染为使用Router进行跳转的a标签,当且仅当 Router 存在时,该 API 有效 - */ - routerLink: Boolean, /** 链接或路由跳转方式 */ target: { type: String as PropType, diff --git a/src/menu/menu-item.tsx b/src/menu/menu-item.tsx index 5ca3f59d8..2c0ea8b0e 100644 --- a/src/menu/menu-item.tsx +++ b/src/menu/menu-item.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-nested-ternary */ import { defineComponent, computed, inject, onMounted, } from '@vue/composition-api'; @@ -41,10 +40,10 @@ export default defineComponent({ menu.select(props.value); ctx.emit('click'); - if (props.to || (props.routerLink && props.href)) { + if (props.to) { const router = props.router || (ctx.root as Record).$router; const methods: string = props.replace ? 'replace' : 'push'; - router[methods](props.to || props.href).catch((err: Error) => { + router[methods](props.to).catch((err: Error) => { // vue-router 3.1.0+ push/replace cause NavigationDuplicated error // https://github.com/vuejs/vue-router/issues/2872 // 当前path和目标path相同时,会抛出NavigationDuplicated的错误 @@ -77,8 +76,6 @@ export default defineComponent({ }; }, render() { - const router = this.router || this.$router; - const liContent = (
  • ).ripple} @@ -86,30 +83,15 @@ export default defineComponent({ onClick={this.handleClick} > {renderTNodeJSX(this, 'icon')} - {this.routerLink ? ( - e.preventDefault()} - > - {renderContent(this, 'default', 'content')} - - ) : this.href ? ( - this.disabled && e.preventDefault()} - > + {this.href ? ( + {renderContent(this, 'default', 'content')} ) : ( - {renderContent(this, 'default', 'content')} + {renderContent(this, 'default', 'content')} )}
  • ); - // 菜单收起,且只有本身为一级菜单才需要显示 tooltip if (this.collapsed && /tmenu/i.test(this.$parent.$vnode?.tag)) { return ( diff --git a/src/menu/type.ts b/src/menu/type.ts index b115ee065..b35896695 100644 --- a/src/menu/type.ts +++ b/src/menu/type.ts @@ -157,7 +157,7 @@ export interface TdMenuItemProps { */ disabled?: boolean; /** - * 跳转链接,菜单项渲染为a标签,当routerLink为true时将使用Router进行路由跳转 + * 跳转链接 * @default '' */ href?: string; @@ -174,10 +174,6 @@ export interface TdMenuItemProps { * 路由对象。如果项目存在 Router,则默认使用 Router。 */ router?: Record; - /** - * 菜单项内容是否渲染为使用Router进行跳转的a标签,当且仅当 Router 存在时,该 API 有效 - */ - routerLink?: boolean; /** * 链接或路由跳转方式 */