I have a vueJs component which looks like the following:
export default {
name: 'componentname',
data () {
return {
items: []
}
},
mounted() {
this.getItems();
},
methods: {
getItems() {
this.$http.get('HTTP_API_ADDRESS').then(res => {
this.items = res.data;
})
}
}
}
I am using in my template a v-for loop on the items in the items array which appear after the call is made to my API.
I have a problem in that the objects in the array contain a boolean which I'm trying to update on page via a click but the object doesn't appear to update on page unless something which was explicitly defined in the instance is updated.
Example, purely an example - code isn't logical.
<ul>
<li v-for="item in items" @click="item.available = !item.available">{{ item.name }} | {{ item.available }}</li>
</ul>
The idea is that the available would display true or false depending on the click for the item.
I believe its to do with the elements of the objects not being defined on mount however I'm unsure how I would do this if they are in an array?