Skip to content

Commit 25807f2

Browse files
committed
fix: TagSelect Infinite loop
1 parent 160ee8c commit 25807f2

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/components/TagSelect/TagSelectOption.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ export default {
2323
}
2424
},
2525
watch: {
26-
'$parent.checkAll' (val) {
26+
'checked' (val) {
2727
this.localChecked = val
28+
},
29+
'$parent.items': {
30+
handler: function (val) {
31+
this.value && val.hasOwnProperty(this.value) && (this.localChecked = val[this.value])
32+
},
33+
deep: true
2834
}
2935
},
3036
render () {

src/components/TagSelect/index.jsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,25 @@ export default {
3434
data () {
3535
return {
3636
expand: false,
37-
checkAll: false,
3837
localCheckAll: false,
39-
items: [],
38+
items: this.getItemsKey(filterEmpty(this.$slots.default)),
4039
val: this.value || this.defaultValue || []
4140
}
4241
},
4342
methods: {
4443
onChange (checked) {
4544
const key = Object.keys(this.items).filter(key => key === checked.value)
4645
this.items[key] = checked.checked
47-
// console.log(this.items)
4846
const bool = Object.values(this.items).lastIndexOf(false)
49-
console.log('bool', bool, 'this.checkAll', this.checkAll)
5047
if (bool === -1) {
51-
!this.checkAll && (this.checkAll = true)
48+
this.localCheckAll = true
5249
} else {
53-
this.checkAll && (this.checkAll = false)
5450
this.localCheckAll = false
5551
}
5652
},
5753
onCheckAll (checked) {
58-
this.checkAll = checked.checked
59-
// Object.keys(this.items)
60-
// this.items[k] = checked.checked
61-
Object.values(this.items).forEach(v => {
62-
v = checked.checked
54+
Object.keys(this.items).forEach(v => {
55+
this.items[v] = checked.checked
6356
})
6457
},
6558
getItemsKey (items) {
@@ -99,8 +92,6 @@ export default {
9992
[`${prefixCls}`]: true
10093
}
10194
const tagItems = filterEmpty(this.$slots.default)
102-
this.items = this.getItemsKey(tagItems)
103-
console.log(this.items)
10495
return (
10596
<div class={classString}>
10697
{this.renderCheckAll()}

0 commit comments

Comments
 (0)