Answer the question
In order to leave comments, you need to log in
How to pass model to custom switch Vue js?
there is a switch component
<template>
<div
class="ivu-switch"
:class="{ 'ivu-switch-checked': isChecked }"
@click.prevent="toggleSwitch"
></div>
</template>
<script>
export default {
data() {
return {
isChecked: false,
}
},
methods: {
toggleSwitch() {
this.isChecked = !this.isChecked
this.$emit('input', this.isChecked)
},
},
}
</script>
<InputSwitch v-model="form.is_published" />
data() {
return {
form: {
is_published: false,
},
}
}
Answer the question
In order to leave comments, you need to log in
data() {
return {
isChecked: false,
}
},
methods: {
toggleSwitch() {
this.isChecked = !this.isChecked
this.$emit('input', this.isChecked)
},
},
props: {
value: Boolean,
},
:class="{ 'ivu-switch-checked': isChecked }"
:class="{ 'ivu-switch-checked': value }"
@click.prevent="toggleSwitch"
@click.prevent="$emit('input', !value)"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question