From 1d2bd12fefde2706722ed468a09479120864dbea Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 15 Jan 2019 21:58:29 +0800 Subject: [PATCH] [improvement] reduce simple computed (#2530) --- packages/address-edit/Detail.js | 69 ++++++++++++++++----------------- packages/address-edit/index.js | 10 ++--- packages/area/index.js | 14 +++---- packages/cell/index.js | 9 +---- 4 files changed, 45 insertions(+), 57 deletions(-) diff --git a/packages/address-edit/Detail.js b/packages/address-edit/Detail.js index 705b46906..a5e1a0c2a 100644 --- a/packages/address-edit/Detail.js +++ b/packages/address-edit/Detail.js @@ -15,19 +15,6 @@ export default sfc({ showSearchResult: Boolean }, - computed: { - searchList() { - if (this.showSearchResult && this.focused) { - return this.searchResult || []; - } - return []; - }, - - showIcon() { - return this.value && this.focused; - } - }, - methods: { onSelect(express) { this.$emit('select-search', express); @@ -36,6 +23,37 @@ export default sfc({ }, render(h) { + const { value, focused, searchResult } = this; + + const Finish = value && focused && android && ( +
{ + this.$refs.field.blur(); + }} + > + {t('complete')} +
+ ); + + const SearchList = + focused && + searchResult && + this.showSearchResult && + searchResult.map(express => ( + { + this.onSelect(express); + }} + /> + )); + return ( - {this.showIcon && android && ( -
{ - this.$refs.field.blur(); - }} - > - {t('complete')} -
- )} + {Finish}
- {this.searchList.map(express => ( - { - this.onSelect(express); - }} - /> - ))} + {SearchList} ); } diff --git a/packages/address-edit/index.js b/packages/address-edit/index.js index a360d5d05..0dd062068 100644 --- a/packages/address-edit/index.js +++ b/packages/address-edit/index.js @@ -74,11 +74,6 @@ export default sfc({ }, computed: { - // hide bottom field when use search && detail get focused - hideBottomFields() { - return this.searchResult.length && this.detailFocused; - }, - areaListLoaded() { return isObj(this.areaList) && Object.keys(this.areaList).length; }, @@ -220,9 +215,12 @@ export default sfc({ }, render(h) { - const { data, errorInfo, hideBottomFields } = this; + const { data, errorInfo } = this; const onFocus = name => () => this.onFocus(name); + // hide bottom field when use search && detail get focused + const hideBottomFields = this.searchResult.length && this.detailFocused; + return (
); } diff --git a/packages/cell/index.js b/packages/cell/index.js index 9bd49e0d8..30d5828be 100644 --- a/packages/cell/index.js +++ b/packages/cell/index.js @@ -14,12 +14,6 @@ export default sfc({ arrowDirection: String }, - computed: { - arrowIcon() { - return this.arrowDirection ? `arrow-${this.arrowDirection}` : 'arrow'; - } - }, - methods: { onClick() { this.$emit('click'); @@ -49,8 +43,9 @@ export default sfc({ this.icon && ); + const arrowIcon = this.arrowDirection ? `arrow-${this.arrowDirection}` : 'arrow'; const RightIcon = slots['right-icon'] || ( - this.isLink && + this.isLink && ); return (