I'm trying to build a triple state checkbox component.
Initially the checkbox value is null and is represented by an indeterminate
checkbox.
When user clicks an indeterminate checkbox the value becomes true, next click false and then again null.
So far this is what I have:
Vue.component('checkbox', {
template: '<input type="checkbox" @change="change" class="checkbox-input">',
props: ['currentSate'],
mounted: function () {
this.currentSate = null;
this.$el.indeterminate = true
},
methods: {
change: function () {
if (this.currentSate == null) {
this.currentSate = true;
this.$el.checked = true;
this.$el.indeterminate = false;
return;
}
if (this.currentSate == true) {
this.currentSate = false
this.$el.checked = false;
this.$el.indeterminate = false;
return;
}
if (this.currentSate == false) {
this.currentSate = null;
this.$el.indeterminate = true;
return;
}
this.$emit('input', this.currentSate);
}
}
});
<checkbox v-bind:current-sate="chState"></checkbox>
chState = {{chState}}
the error I'm getting is:
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "currentSate"
How can this be accomplished?