1
Explanation of the problem
Have this javascript in html I call v-on:click="sync"
it updates the news list, but this news list until I click Sync it goes blank, so I’m looking for a way to make the v-on:click="sync"
on something automatic that when I open HTML the news list is automatically updated.
The Javascript to follow
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();
}
})
}
window onload.
– BrTkCa
I suggest editing the title. It can be more descriptive than it is currently.
– Wallace Maxters
What version of Vue are you using? 1 or 2?
– bfavaretto
I’m using version 1
– Yuri Ruan