There are 2 toggle buttons. If the value is true, then add to the array, otherwise remove the element.
data:
originality: []
toggles:
<toggle id='1' ref='toggleOriginal'> Click </toggle>
<toggle id='2' ref='toggleAnalog'> Click </toggle>
methods:
if(this.$refs.toggleOriginal.isActive) {
this.originality.push(this.$refs.toggleOriginal.id);
} else {
this.originality = this.originality.filter((item) => {
return item == this.$refs.toggleOriginal.id;
});
}
if(this.$refs.toggleAnalog.isActive) {
this.originality.push(this.$refs.toggleAnalog.id);
} else {
this.originality = this.originality.filter((item) => {
return item == this.$refs.toggleAnalog.id;
});
}
And the same for the second. In isActive I check for true / false.
the problem is that if two toggle is true and I want to convert one to false, then the wrong element is removed. Perhaps you should use a different functionality?
v-modelto link the toggle's state to a variable (for example it's ID). You can then use acomputed valueto create theoriginalityarray. No need to juggle their values manually.v-modelfor a component. Is not it?v-modelfor a component. That is a reason it exists, so you don't have to juggle the value manually between each component.