Salve a tutti, sono nuovo sul forum. Ho una leggera difficoltà quando si parla di javascript, e per un esame mi è stato chiesto di fare un sito che utilizzi NewsApi.
Ora la struttura che posseggo mi permette di visualizzare autore, titolo e contenuto di un articolo, ma non riesco a visualizzare l'immagine. Il codice nel Html per richiamare le tre cose citate prima delle notizie è questo:
<div v-for="x in prova">
<div class="container">
<div class="row">
<h2>{{x.title}}</h2>
<h6>{{x.author}}</h6>
<h5>{{x.content}}</h5>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/vue.js"></script>
<script src="js/newsapi.js"></script>
</div> <!--Chiusura Div Class=App-->
</body>
</html>
Mentre nel .js ho questo:
var app = new Vue({
el:"#app",
data:{
q:null,
cat:null,
prova:[
{a:"a1", b:"b1"},
{a:"a2", b:"b2"},
{a:"a3", b:"b3"}
]
},
methods:{
refresh:function(){
var me = this;
var key = "39cce8ed64e5447cb8cc2ba1fd33af19";
url = "https://newsapi.org/v2/top-headlines?";
if(me.q){
url += "q=" + me.q + "&";
};
if(me.cat){
url+="category" + me.cat + "&";
}
url +="category=general&country=it&apiKey=39cce8ed64e544 7cb8cc2ba1fd33af19";
$.getJSON (url, function(resp){
me.prova = resp.articles;
});
},
mounted:function(){
this.refresh();
}
}
});
Mi serve un aiuto per sapere come si fa a richiamare le immagini dal NewsApi, ho provato alcuni tag, ma si son rivelati sbagliati, anche perchè sono andato a tentativi, e si stava rivelando inutile.