From 3b50cc4c6838b2d3e7686f348af902570320bc80 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Thu, 9 Sep 2021 00:17:18 +0800 Subject: [PATCH] refactor(cascader): clean code --- src/cascader/src/CascaderMenu.tsx | 118 ++++++++++++++---------------- 1 file changed, 56 insertions(+), 62 deletions(-) diff --git a/src/cascader/src/CascaderMenu.tsx b/src/cascader/src/CascaderMenu.tsx index f494274d8..0363ee213 100644 --- a/src/cascader/src/CascaderMenu.tsx +++ b/src/cascader/src/CascaderMenu.tsx @@ -132,70 +132,64 @@ export default defineComponent({ return ( {{ - default: () => - this.show - ? withDirectives( + default: () => { + if (!this.show) return null + return withDirectives( +
+ {this.menuModel[0].length ? ( +
+ {this.menuModel.map((submenuOptions, index) => ( + { + if (instance) { + submenuInstRefs[index] = instance + } + }) as any + } + key={index} + tmNodes={submenuOptions} + depth={index + 1} + /> + ))} + +
+ ) : ( +
+ {renderSlot($slots, 'empty', undefined, () => [])} +
+ )} + {$slots.action && (
- {this.menuModel[0].length ? ( -
- {this.menuModel.map((submenuOptions, index) => { - return ( - { - if (instance) { - submenuInstRefs[index] = instance - } - }) as any - } - key={index} - tmNodes={submenuOptions} - depth={index + 1} - /> - ) - })} - -
- ) : ( -
- {renderSlot($slots, 'empty', undefined, () => [ - - ])} -
- )} - {$slots.action ? ( -
- {{ - default: $slots.action - }} -
- ) : null} - -
, - [[clickoutside, this.handleClickOutside]] - ) - : null + {{ + default: $slots.action + }} +
+ )} + + , + [[clickoutside, this.handleClickOutside]] + ) + } }}
)