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>
|
<template>
|
||||||
<button class="button is-rounded"
|
<button class="button is-rounded"
|
||||||
:class="checked ? checked_class : unchecked_class"
|
:class="shouldBeChecked ? checked_class : unchecked_class"
|
||||||
v-on:click="click"
|
v-on:click="updateInput"
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</button>
|
</button>
|
||||||
@ -10,22 +10,52 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'button-checkbox',
|
name: 'button-checkbox',
|
||||||
|
model: {
|
||||||
|
prop: 'checked',
|
||||||
|
event: 'change'
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
checked_class: {
|
checked_class: {
|
||||||
default: 'is-info'
|
default: 'is-info'
|
||||||
},
|
},
|
||||||
unchecked_class: {
|
unchecked_class: {
|
||||||
default: ''
|
default: ''
|
||||||
|
},
|
||||||
|
checked: {
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
value: String,
|
||||||
|
trueValue: {
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
falseValue: {
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
computed: {
|
||||||
return {
|
shouldBeChecked () {
|
||||||
checked: true
|
if (this.checked instanceof Array) {
|
||||||
|
return this.checked.includes(this.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.checked === this.trueValue
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
click () {
|
updateInput () {
|
||||||
this.checked = !this.checked
|
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