From 1dd4083102272250637d6397bd98355d87d99bf5 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Tue, 6 Oct 2020 16:26:31 +0800 Subject: [PATCH] fix(ContactList): select event triggered twice --- src/contact-list/index.js | 137 +++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 75 deletions(-) diff --git a/src/contact-list/index.js b/src/contact-list/index.js index 7dcf1a929..5fbbdf688 100644 --- a/src/contact-list/index.js +++ b/src/contact-list/index.js @@ -23,89 +23,76 @@ export default createComponent({ emits: ['add', 'edit', 'select', 'update:modelValue'], setup(props, { emit }) { - return () => { - const List = - props.list && - props.list.map((item, index) => { - function onClick() { - emit('update:modelValue', item.id); - emit('select', item, index); - } + const renderItem = (item, index) => { + const onClick = () => { + emit('update:modelValue', item.id); + emit('select', item, index); + }; - function RightIcon() { - return ( - - ); - } + const renderRightIcon = () => ( + + ); - function LeftIcon() { - return ( - { - event.stopPropagation(); - emit('edit', item, index); - }} - /> - ); - } + const renderLeftIcon = () => ( + { + event.stopPropagation(); + emit('edit', item, index); + }} + /> + ); - function Content() { - const nodes = [`${item.name},${item.tel}`]; + const renderContent = () => { + const nodes = [`${item.name},${item.tel}`]; - if (item.isDefault && props.defaultTagText) { - nodes.push( - - {props.defaultTagText} - - ); - } - - return nodes; - } - - return ( - + if (item.isDefault && props.defaultTagText) { + nodes.push( + + {props.defaultTagText} + ); - }); + } + + return nodes; + }; return ( -
- - {List} - -
-
-
+ ); }; + + return () => ( +
+ + {props.list && props.list.map(renderItem)} + +
+
+
+ ); }, });