I am making a request to API
with Vue
to adapt it with Rail
, but when I print the data on the screen it sends me empty, this is the connection to API
:
main.js:
var urlAPI = 'xxxxxxxxxx';
new Vue({
el: 'body',
created: function() {
this.consultaAPI();
},
data: {
personas: []
},
methods: {
consultaAPI: function() {
this.$http.get(urlAPI)
.then(function(respuesta) {
this.personas = respuesta.data.results;
});
}
},
components: {
'personas': {
template: '#personas-template',
props: ['lista']
}
}
});
Then I do the deployment in the html:
<personas :lista="personas"></personas>
<template id="personas-template">
<ul v-for="persona in lista">
<li>{{ persona.name}}</li>
</ul>
</template>
<pre>
{{ $data | json}}
</pre>
And it does not send the information when I do the inspection of the data through the browser sends me the following.
I would appreciate if you could indicate to me if I am omitting something.