Software Archive
Read-only legacy content
17060 Discussions

como por javascript para rodar automaticamente no Córdova utilizando o vue.js

yuri_r_
Beginner
149 Views

Este código esta atualizando a lista de dados puxadas do banco de dados apenas quando o botão sync e acionado gostaria que ele atualizasse assim que o app abrir.

document.addEventListener("deviceready",onDeviceReady,true);
function onDeviceReady(){
var vm = new Vue({
		el: '#app',
		data:{
			noticias: []
		},
		methods:{
			sync:function(){
				$.ajax({
					dataType: 'json',
					url: 'http://example.com/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();
		}
	})
}

 

0 Kudos
1 Reply
Giselle_G_Intel
Employee
149 Views

First off, it looks like your sync function is defined on its own. Do you connect this 'sync button' to the sync function somewhere else - or does this define that button? What I suggest is in the ready function you defined, you call the sync function from up above. Much like you call the setNoticias function, this way once the device is ready, you fire the function that pulls from the database and then updates.

0 Kudos
Reply