I'm facing an issue with my dynamic array "slots" of objects which looks something like this:
[{"availability": 1},{"availability": 3}]
I render multiple inputs in Vue.js using v-for like so:
<div v-for="slot in array"><input v-model="slot.availability></input></div>
Then, I add a watcher to monitor if any object's value increases by more than 10. If it does, I reset it to 10 as shown below:
watch: {
slots: {
handler() {
this.slots.forEach(slot => {
if (slot.availability > 10) slot.availability = 10;
});
},
deep: true
}
}
However, this only works the first time. For instance, if I type '99', it resets to 10. But if I continue typing '9', it doesn't change '109' to '10'. The resetting to 10 only happens when I click away from the input field. I believe there might be a solution using a computed property, but I'm not sure how to implement it. Any assistance would be highly appreciated!