Using Vue.js 2. I have a list of objects I'm displaying to the user. An entity of that object specifically. Here's a screen of the object (only showing 1 for brevity) and the list it's displayed in
<v-sheet elevation="10" rounded class="py-4 px-1">
<div class="text-center text-caption">
Device Serial Number {{ this.deviceOptions.length }}
</div>
<v-chip-group
multiple
active-class="primary--text"
v-model="deviceOptions"
>
<v-chip
v-for="item in $store.state.responeArray"
:key="item.key"
@click="countDevices(item)" // pass this selected object to a method
>
{{ item.DeviceSerialNumber }}
</v-chip>
</v-chip-group>
</v-sheet>
When one of these items are clicked I pass the item object to a method where I add the CollectionId to an array if it doesn't exist.
The object gets passed correctly, and I check if it exists in the array. If it doesn't, I add it. If I deselect, I check and remove it. here's that method.
countDevices(e) {
if (this.deviceOptions.indexOf(e.CollectionId) >= 0) {
for(let i = 0; i < this.deviceOptions.length; i++) {
if (this.deviceOptions[i] === e.CollectionId){
this.deviceOptions.splice(i, 1);
}
}
console.log(this.deviceOptions.length);
console.log(this.deviceOptions);
} else {
this.deviceOptions.unshift(e.CollectionId);
console.log(this.deviceOptions.length);
console.log(this.deviceOptions);
}
},
The actual problem
However, when you add to the array, it adds two values. not just one. I can't tell what that extra value is, but I think it's the observer vue uses.
Take notice of the length displayed that console where the value is present and observer
There's only one item selected, but length is showing 2. Whereas my goal is to show the counted number of indexes within the array.
Can anyone assist in this?