[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 {
padding: 0 5px;
color: @gray-dark;
color: @text-color;
&--selected {
font-weight: 500;
color: @text-color;
}
&--disabled {

View File

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

View File

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

View File

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