mirror of
https://github.com/kihashi/stardew_community_checklist.git
synced 2025-10-19 08:03:17 +00:00
Fixed event propogation to work with arrays.
This commit is contained in:
parent
b7f39e240e
commit
294e25b30d
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<button class="button is-rounded"
|
||||
:class="checked ? checked_class : unchecked_class"
|
||||
v-on:click="click"
|
||||
:class="shouldBeChecked ? checked_class : unchecked_class"
|
||||
v-on:click="updateInput"
|
||||
>
|
||||
<slot></slot>
|
||||
</button>
|
||||
@ -10,22 +10,52 @@
|
||||
<script>
|
||||
export default {
|
||||
name: 'button-checkbox',
|
||||
model: {
|
||||
prop: 'checked',
|
||||
event: 'change'
|
||||
},
|
||||
props: {
|
||||
checked_class: {
|
||||
default: 'is-info'
|
||||
},
|
||||
unchecked_class: {
|
||||
default: ''
|
||||
},
|
||||
checked: {
|
||||
default: false
|
||||
},
|
||||
value: String,
|
||||
trueValue: {
|
||||
default: true
|
||||
},
|
||||
falseValue: {
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
checked: true
|
||||
computed: {
|
||||
shouldBeChecked () {
|
||||
if (this.checked instanceof Array) {
|
||||
return this.checked.includes(this.value)
|
||||
}
|
||||
|
||||
return this.checked === this.trueValue
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
click () {
|
||||
this.checked = !this.checked
|
||||
updateInput () {
|
||||
if (this.checked instanceof Array) {
|
||||
let newValue = [...this.checked]
|
||||
|
||||
if (!this.shouldBeChecked) {
|
||||
newValue.push(this.value)
|
||||
} else {
|
||||
newValue.splice(newValue.indexOf(this.value), 1)
|
||||
}
|
||||
|
||||
this.$emit('change', newValue)
|
||||
} else {
|
||||
this.$emit('change', this.shouldBeChecked ? this.falseValue : this.trueValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user