Skip to content

Commit fa3dd1f

Browse files
OuZuYulevy9527
authored andcommitted
fix: 默认值为空数组,但使用resetFields重置表单后,值不为空数组
close #10
1 parent 2950f2b commit fa3dd1f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/el-select-area.vue

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ const AREA = {
3737
}
3838
}
3939
40+
const TYPE = {
41+
all: 'all',
42+
code: 'code',
43+
text: 'text'
44+
}
45+
4046
function isCode(value = '') {
4147
return /^\d{6,}$/.test(value)
4248
}
@@ -208,22 +214,25 @@ export default {
208214
},
209215
// 兼容旧的输出
210216
emitEvent() {
217+
const type = this.type
211218
let result
212219
213-
if (this.type === 'all') {
214-
result = this.values.map(item => {
215-
const obj = {}
216-
item.code && (obj[item.code] = item.name)
217-
return obj
218-
})
219-
}
220-
221-
if (this.type === 'code') {
222-
result = this.values.map(item => item.code)
223-
}
220+
if (type === TYPE.all) {
221+
result = this.values
222+
.map(item => {
223+
const obj = {}
224+
item.code && (obj[item.code] = item.name)
225+
return obj
226+
})
227+
.filter(v => Object.keys(v).length)
228+
} else {
229+
if (type === TYPE.code) {
230+
result = this.values.map(item => item.code)
231+
} else if (type === TYPE.text) {
232+
result = this.values.map(item => item.name)
233+
}
224234
225-
if (this.type === 'text') {
226-
result = this.values.map(item => item.name)
235+
result = result.filter(v => v)
227236
}
228237
229238
result = result.slice(0, +this.level + 1)

0 commit comments

Comments
 (0)