From 44194c711eb884c2767a66d42e40bed938c2a1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuli=E9=94=A4=E9=94=A4?= <980198595@qq.com> Date: Wed, 8 Jul 2020 15:43:01 +0800 Subject: [PATCH] fix(Area): When setting the attribute [columns-num=1 or columns-num=2] lower than the WeChat basic library version 2.7.7, the real machine environment reports an error (#3318) --- packages/area/index.ts | 43 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/area/index.ts b/packages/area/index.ts index c2c9a21a..e647570a 100644 --- a/packages/area/index.ts +++ b/packages/area/index.ts @@ -201,31 +201,34 @@ VantComponent({ } const stack = []; + const indexes = []; - stack.push(picker.setColumnValues(0, province, false)); - stack.push(picker.setColumnValues(1, city, false)); - - if (city.length && code.slice(2, 4) === '00') { - [{ code }] = city; + if (this.data.columnsNum >= 1) { + stack.push(picker.setColumnValues(0, province, false)); + indexes.push(this.getIndex('province', code)); } - stack.push( - picker.setColumnValues( - 2, - this.getList('county', code.slice(0, 4)), - false - ) - ); + if (this.data.columnsNum >= 2) { + stack.push(picker.setColumnValues(1, city, false)); + indexes.push(this.getIndex('province', code)); + if (city.length && code.slice(2, 4) === '00') { + [{ code }] = city; + } + } + + if (this.data.columnsNum === 3) { + stack.push( + picker.setColumnValues( + 2, + this.getList('county', code.slice(0, 4)), + false + ) + ); + } return Promise.all(stack) .catch(() => {}) - .then(() => - picker.setIndexes([ - this.getIndex('province', code), - this.getIndex('city', code), - this.getIndex('county', code), - ]) - ) + .then(() => picker.setIndexes(indexes)) .catch(() => {}); }, @@ -267,4 +270,4 @@ VantComponent({ return this.setValues(); }, }, -}); +}); \ No newline at end of file