mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-05 19:41:45 +08:00
[bugfix] Area: error when list empty (#661)
This commit is contained in:
parent
677a980c15
commit
b8fb181b66
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,24 @@
|
||||
import Page from '../../common/page';
|
||||
import AreaList from './area';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
areaList: AreaList,
|
||||
areaList: {},
|
||||
loading: true,
|
||||
value: 330302
|
||||
},
|
||||
|
||||
onShow() {
|
||||
wx.request({
|
||||
url: 'https://cashier.youzan.com/pay/wsctrade/order/buy/getAllRegion.json',
|
||||
success: response => {
|
||||
this.setData({
|
||||
loading: false,
|
||||
areaList: response.data.data
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onChange(event) {
|
||||
console.log(event);
|
||||
}
|
||||
|
@ -1,11 +1,25 @@
|
||||
<demo-block title="基础用法">
|
||||
<van-area area-list="{{ areaList }}" />
|
||||
<van-area
|
||||
loading="{{ loading }}"
|
||||
area-list="{{ areaList }}"
|
||||
/>
|
||||
</demo-block>
|
||||
|
||||
<demo-block title="选中省市县">
|
||||
<van-area area-list="{{ areaList }}" value="{{ value }}" />
|
||||
<van-area
|
||||
value="{{ value }}"
|
||||
loading="{{ loading }}"
|
||||
area-list="{{ areaList }}"
|
||||
/>
|
||||
</demo-block>
|
||||
|
||||
<demo-block title="配置显示列">
|
||||
<van-area area-list="{{ areaList }}" columns-num="{{ 2 }}" title="标题" bind:confirm="onChange" bind:change="onChange" />
|
||||
<van-area
|
||||
title="标题"
|
||||
columns-num="{{ 2 }}"
|
||||
loading="{{ loading }}"
|
||||
area-list="{{ areaList }}"
|
||||
bind:change="onChange"
|
||||
bind:confirm="onChange"
|
||||
/>
|
||||
</demo-block>
|
||||
|
@ -68,13 +68,13 @@ VantComponent({
|
||||
const { value } = event.detail;
|
||||
const { pickerValue, displayColumns } = this.data;
|
||||
const index = pickerValue.findIndex((item, index) => item !== value[index]);
|
||||
const values = displayColumns[index];
|
||||
|
||||
// 没有变更 或 选中项序号小于0 不处理
|
||||
if (index < 0 || value[index] < 0) {
|
||||
if (!value[index] || !values[value[index]]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const values = displayColumns[index];
|
||||
|
||||
this.code = values[value[index]].code;
|
||||
this.setValues();
|
||||
this.$emit('change', {
|
||||
@ -118,7 +118,7 @@ VantComponent({
|
||||
},
|
||||
|
||||
setValues() {
|
||||
let code = this.code || Object.keys(this.data.areaList.county_list)[0] || '';
|
||||
let code = this.code || Object.keys(this.data.areaList.county_list || {})[0] || '';
|
||||
const province = this.getList('province');
|
||||
const city = this.getList('city', code.slice(0, 2));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user