Skip to content

Instantly share code, notes, and snippets.

@acoshift
Created January 3, 2017 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoshift/6349cc96fd42617930a50f58795bcced to your computer and use it in GitHub Desktop.
Save acoshift/6349cc96fd42617930a50f58795bcced to your computer and use it in GitHub Desktop.
vuejs-semantic-checkbox
<template lang="pug">
.ui.checkbox
input(ref='input', type='checkbox')
label
slot
</template>
<script>
export default {
props: ['value'],
data () {
return {
holdEvent: false
}
},
mounted () {
this.$nextTick(() => {
$(this.$el).checkbox(this.value && 'check' || 'uncheck')
this.$nextTick(() => {
$(this.$el)
.checkbox({
onChecked: () => {
if (this.holdEvent) return
this.$emit('input', true)
this.$emit('change')
},
onUnchecked: () => {
if (this.holdEvent) return
this.$emit('input', false)
this.$emit('change')
}
})
})
})
},
destroyed () {
$(this.$el).off()
},
watch: {
value (value) {
this.holdEvent = true
$(this.$el).checkbox(value && 'check' || 'uncheck')
this.$nextTick(() => {
this.holdEvent = false
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment