I am using Vuetify checkbox (which I don't think is relevant, this is probably caused by Vue itself), and trying to get an array of checkbox double binding with an array of true, false value. By controlling the true/false value of each element, I want to control the checking status of the checkbox. Here is an example code in fiddle that WORKS with a SINGLE element:
HTML:
<v-checkbox v-model="selected" label="John"> </v-checkbox>
<v-btn @click="toggle">toggle</v-btn>
Script:
toggle () {
this.selected=!this.selected
console.log(this.selected)
}
This works: https://jsfiddle.net/ziranshu/evsatguy/12
However, when I put the v-model values into an array: html:
<v-checkbox v-model="selected[0]" label="John"> </v-checkbox>
<v-btn @click="toggle(0)">toggle John</v-btn>
script:
toggle (index) {
this.selected[index]=!this.selected[index]
console.log(this.selected)
}
It's NOT working anymore: https://jsfiddle.net/ziranshu/evsatguy/20
I can't think of any difference between binding with an array element and binding with a single value. Can anyone explain, and suggest how to fix this?