[improvement] Area: optimize performance (#1055)

This commit is contained in:
neverland 2018-12-11 19:17:53 +08:00 committed by GitHub
parent 353b8288d4
commit 97476fec76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 14 deletions

View File

@ -57,11 +57,10 @@
&__item { &__item {
padding: 0 5px; padding: 0 5px;
color: @gray-dark; color: @text-color;
&--selected { &--selected {
font-weight: 500; font-weight: 500;
color: @text-color;
} }
&--disabled { &--disabled {

View File

@ -33,13 +33,6 @@ VantComponent({
columns: [] columns: []
}, },
computed: {
displayColumns() {
const { columns = [], columnsNum } = this.data;
return columns.slice(0, +columnsNum);
}
},
watch: { watch: {
value(value) { value(value) {
this.code = value; this.code = value;
@ -68,7 +61,8 @@ VantComponent({
onChange(event: Weapp.Event) { onChange(event: Weapp.Event) {
const { value } = event.detail; const { value } = event.detail;
const { pickerValue, displayColumns } = this.data; const { pickerValue } = this.data;
const displayColumns = this.getDisplayColumns();
const index = pickerValue.findIndex( const index = pickerValue.findIndex(
(item, index) => item !== value[index] (item, index) => item !== value[index]
); );
@ -159,7 +153,8 @@ VantComponent({
}, },
getValues() { getValues() {
const { displayColumns = [], pickerValue = [] } = this.data; const { pickerValue = [] } = this.data;
const displayColumns = this.getDisplayColumns();
return displayColumns return displayColumns
.map((option, index) => option[pickerValue[index]]) .map((option, index) => option[pickerValue[index]])
.filter(value => !!value); .filter(value => !!value);
@ -201,6 +196,11 @@ VantComponent({
reset() { reset() {
this.code = ''; this.code = '';
this.setValues(); this.setValues();
},
getDisplayColumns() {
const { columns = [], columnsNum } = this.data;
return columns.slice(0, +columnsNum);
} }
} }
}); });

View File

@ -17,7 +17,8 @@
class="van-picker__columns" class="van-picker__columns"
> >
<picker-view-column <picker-view-column
wx:for="{{ displayColumns }}" wx:if="{{ rowIndex < columnsNum }}"
wx:for="{{ columns }}"
wx:for-item="row" wx:for-item="row"
wx:for-index="rowIndex" wx:for-index="rowIndex"
wx:key="rowIndex" wx:key="rowIndex"

View File

@ -1,5 +1,5 @@
function isArray(obj) { function isArray(array) {
return obj && obj.constructor === 'Array'; return array && array.constructor === 'Array';
} }
module.exports.isArray = isArray; module.exports.isArray = isArray;