mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] reduce simple computed (#2530)
This commit is contained in:
parent
f41b9d3bd3
commit
1d2bd12fef
@ -15,19 +15,6 @@ export default sfc({
|
|||||||
showSearchResult: Boolean
|
showSearchResult: Boolean
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
searchList() {
|
|
||||||
if (this.showSearchResult && this.focused) {
|
|
||||||
return this.searchResult || [];
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
},
|
|
||||||
|
|
||||||
showIcon() {
|
|
||||||
return this.value && this.focused;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onSelect(express) {
|
onSelect(express) {
|
||||||
this.$emit('select-search', express);
|
this.$emit('select-search', express);
|
||||||
@ -36,6 +23,37 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render(h) {
|
||||||
|
const { value, focused, searchResult } = this;
|
||||||
|
|
||||||
|
const Finish = value && focused && android && (
|
||||||
|
<div
|
||||||
|
slot="icon"
|
||||||
|
class={bem('finish')}
|
||||||
|
onClick={() => {
|
||||||
|
this.$refs.field.blur();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('complete')}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const SearchList =
|
||||||
|
focused &&
|
||||||
|
searchResult &&
|
||||||
|
this.showSearchResult &&
|
||||||
|
searchResult.map(express => (
|
||||||
|
<Cell
|
||||||
|
key={express.name + express.address}
|
||||||
|
title={express.name}
|
||||||
|
label={express.address}
|
||||||
|
icon="location-o"
|
||||||
|
clickable
|
||||||
|
onClick={() => {
|
||||||
|
this.onSelect(express);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Cell class={bem()}>
|
<Cell class={bem()}>
|
||||||
<Field
|
<Field
|
||||||
@ -51,30 +69,9 @@ export default sfc({
|
|||||||
placeholder={t('placeholder')}
|
placeholder={t('placeholder')}
|
||||||
{...{ on: this.$listeners }}
|
{...{ on: this.$listeners }}
|
||||||
>
|
>
|
||||||
{this.showIcon && android && (
|
{Finish}
|
||||||
<div
|
|
||||||
slot="icon"
|
|
||||||
class={bem('finish')}
|
|
||||||
onClick={() => {
|
|
||||||
this.$refs.field.blur();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('complete')}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Field>
|
</Field>
|
||||||
{this.searchList.map(express => (
|
{SearchList}
|
||||||
<Cell
|
|
||||||
key={express.name + express.address}
|
|
||||||
title={express.name}
|
|
||||||
label={express.address}
|
|
||||||
icon="location-o"
|
|
||||||
clickable
|
|
||||||
onClick={() => {
|
|
||||||
this.onSelect(express);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,6 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
// hide bottom field when use search && detail get focused
|
|
||||||
hideBottomFields() {
|
|
||||||
return this.searchResult.length && this.detailFocused;
|
|
||||||
},
|
|
||||||
|
|
||||||
areaListLoaded() {
|
areaListLoaded() {
|
||||||
return isObj(this.areaList) && Object.keys(this.areaList).length;
|
return isObj(this.areaList) && Object.keys(this.areaList).length;
|
||||||
},
|
},
|
||||||
@ -220,9 +215,12 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render(h) {
|
||||||
const { data, errorInfo, hideBottomFields } = this;
|
const { data, errorInfo } = this;
|
||||||
const onFocus = name => () => this.onFocus(name);
|
const onFocus = name => () => this.onFocus(name);
|
||||||
|
|
||||||
|
// hide bottom field when use search && detail get focused
|
||||||
|
const hideBottomFields = this.searchResult.length && this.detailFocused;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={bem()}>
|
<div class={bem()}>
|
||||||
<Field
|
<Field
|
||||||
|
@ -41,13 +41,6 @@ export default sfc({
|
|||||||
|
|
||||||
displayColumns() {
|
displayColumns() {
|
||||||
return this.columns.slice(0, +this.columnsNum);
|
return this.columns.slice(0, +this.columnsNum);
|
||||||
},
|
|
||||||
|
|
||||||
listeners() {
|
|
||||||
return {
|
|
||||||
...this.$listeners,
|
|
||||||
change: this.onChange
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -186,6 +179,11 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render(h) {
|
||||||
|
const on = {
|
||||||
|
...this.$listeners,
|
||||||
|
change: this.onChange
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Picker
|
<Picker
|
||||||
ref="picker"
|
ref="picker"
|
||||||
@ -197,7 +195,7 @@ export default sfc({
|
|||||||
columns={this.displayColumns}
|
columns={this.displayColumns}
|
||||||
itemHeight={this.itemHeight}
|
itemHeight={this.itemHeight}
|
||||||
visibleItemCount={this.visibleItemCount}
|
visibleItemCount={this.visibleItemCount}
|
||||||
{...{ on: this.listeners }}
|
{...{ on }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,6 @@ export default sfc({
|
|||||||
arrowDirection: String
|
arrowDirection: String
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
arrowIcon() {
|
|
||||||
return this.arrowDirection ? `arrow-${this.arrowDirection}` : 'arrow';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onClick() {
|
onClick() {
|
||||||
this.$emit('click');
|
this.$emit('click');
|
||||||
@ -49,8 +43,9 @@ export default sfc({
|
|||||||
this.icon && <Icon class={bem('left-icon')} name={this.icon} />
|
this.icon && <Icon class={bem('left-icon')} name={this.icon} />
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const arrowIcon = this.arrowDirection ? `arrow-${this.arrowDirection}` : 'arrow';
|
||||||
const RightIcon = slots['right-icon'] || (
|
const RightIcon = slots['right-icon'] || (
|
||||||
this.isLink && <Icon class={bem('right-icon')} name={this.arrowIcon} />
|
this.isLink && <Icon class={bem('right-icon')} name={arrowIcon} />
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user