Explaining the problem
I have this javascript that in the html I call v-on:click="sync"
it updates the news list, but this news list while I do not click on sync it goes blank, so I'm looking for a way to make v-on:click="sync"
on something automatic that when I open the HTML the news list is updated automatically.
The following JavaScript
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady(){
var vm = new Vue({
el: '#app',
data:{
noticias: []
},
methods:{
sync:function(){
$.ajax({
dataType: 'json',
url: 'http://example/read.php',
success:function(dados){
localStorage.setItem('noticias',JSON.stringify(dados));
vm.setNoticias();
},
error:function(){
alert("ocorreu um erro durante a conexão com o servidor!");
}
});
},
setNoticias:function(){
this.noticias = JSON.parse(localStorage.getItem('noticias'));
console.log(this.noticias);
}
},
ready:function(){
this.setNoticias();
}
})
}