mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 18:00:27 +08:00
[bugfix] Area: should valid data before get area list (#520)
This commit is contained in:
parent
9634bc6ae4
commit
0b33cbddb6
@ -35,11 +35,14 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
listValid() {
|
||||||
|
return this.areaList && typeof this.areaList.province_list === 'object';
|
||||||
|
},
|
||||||
|
|
||||||
columns() {
|
columns() {
|
||||||
const columns = [];
|
const columns = [];
|
||||||
const { areaList } = this;
|
|
||||||
|
|
||||||
if (!areaList || typeof areaList.province_list !== 'object') {
|
if (!this.listValid) {
|
||||||
return columns;
|
return columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +94,10 @@ export default create({
|
|||||||
|
|
||||||
// 根据省市县类型和对应的`code`获取对应列表
|
// 根据省市县类型和对应的`code`获取对应列表
|
||||||
getList(type, code) {
|
getList(type, code) {
|
||||||
|
if (!this.listValid) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const { areaList } = this;
|
const { areaList } = this;
|
||||||
const list =
|
const list =
|
||||||
type === 'province'
|
type === 'province'
|
||||||
@ -118,11 +125,10 @@ export default create({
|
|||||||
getIndex(type, code) {
|
getIndex(type, code) {
|
||||||
const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
|
||||||
const areaList = this.getList(type, code.slice(0, compareNum - 2));
|
const areaList = this.getList(type, code.slice(0, compareNum - 2));
|
||||||
|
code = code.slice(0, compareNum);
|
||||||
|
|
||||||
for (let i = 0; i < areaList.length; i++) {
|
for (let i = 0; i < areaList.length; i++) {
|
||||||
if (
|
if (areaList[i].code.slice(0, compareNum) === code) {
|
||||||
+areaList[i].code.slice(0, compareNum) === +code.slice(0, compareNum)
|
|
||||||
) {
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user