how can you change the value of an array 'reactively' by using Vue.js
data:{
cafe:[
{dish:’chips’},
{dish:’smokies’},
{dish:’hotdogs’},
(juice:’mango’)
]
}
suppose you want to change "chips" to "fish"
Use $set for setting value.
this.$set(this.cafe[0],'dish','fish');
You could change your data structure a little bit, to make it more accessable.
data:{
cafe: {
dish: ["chips", "smokies", "hotdogs"],
juice: ["mango"]
}
}
Then, you can filter a little bit easier.
this.cafe.dish = [...this.cafe.dish.filter(value => value !== "chips"), "fish"]
The dish array get's filtered and returns all values except chips, then you create a new array from the filter return and put in the fish.
this.cafe[0].dish = 'fish';