save selected items to the state
This commit is contained in:
parent
d9b3f5be47
commit
e0b2463750
2 changed files with 26 additions and 1 deletions
|
@ -8,6 +8,31 @@ const SelectableList = {
|
|||
items: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
getKey: {
|
||||
type: Function,
|
||||
default: item => item
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
selected: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggle (checked, item) {
|
||||
const oldChecked = this.isChecked(item)
|
||||
if (checked !== oldChecked) {
|
||||
const key = this.getKey(item)
|
||||
if (checked) {
|
||||
this.selected.push(key)
|
||||
} else {
|
||||
this.selected.splice(this.selected.indexOf(key), 1)
|
||||
}
|
||||
}
|
||||
},
|
||||
isChecked (item) {
|
||||
return this.selected.indexOf(this.getKey(item)) !== -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue