I have a list of items, which I want to update when I update the array. This is my list of items:
<li v-for="page in pages" class="menu__item">
<a class="menu__link" @click="currentPage = page.id">{{ page.title }}</a>
</li>
I have a variable which is an array:
data: {
pages: [],
menuVisible: false
},
I have a watch set up which updates the variable when required:
watch: {
'menuVisible': function(val, oldVal) {
$.getJSON('/pages/json/list.json', function(json){
this.pages = json;
});
}
}
When "menuVisible" updates, it fires this, and the var changes, but the list does not.
To give a basic idea of what I am trying to achieve; I have a list of pages. A new page is created via a ajax submit. When the user opens the menu with the list of pages, it updates menuVisible
, which in turn updates the variable. I want it to update the list of pages, but it does not.
What am I missing?