mirror of
https://git.youjo.love/youjo/youjo-fe.git
synced 2025-02-08 14:33:37 +01:00
32 lines
626 B
JavaScript
32 lines
626 B
JavaScript
import List from '../list/list.vue'
|
|
import Checkbox from '../checkbox/checkbox.js'
|
|
|
|
const SelectableList = {
|
|
components: {
|
|
List,
|
|
Checkbox
|
|
},
|
|
props: List.props,
|
|
data () {
|
|
return {
|
|
selected: []
|
|
}
|
|
},
|
|
methods: {
|
|
toggle (checked, key) {
|
|
const oldChecked = this.isSelected(key)
|
|
if (checked !== oldChecked) {
|
|
if (checked) {
|
|
this.selected.push(key)
|
|
} else {
|
|
this.selected.splice(this.selected.indexOf(key), 1)
|
|
}
|
|
}
|
|
},
|
|
isSelected (key) {
|
|
return this.selected.indexOf(key) !== -1
|
|
}
|
|
}
|
|
}
|
|
|
|
export default SelectableList
|