简体   繁体   English

Vue和API:显示图像

[英]Vue and API: Displaying Image

I am currently using Vue JS and the data is coming from API . 我目前正在使用Vue JS,数据来自API。 to call a data from API I use this method {{services.service_picture}}. 从API调用数据,我使用此方法{{services.service_picture}}。

But the problem is I am unable to display the image with this method below. 但是问题是我无法使用下面的方法显示图像。 Can you please send some ideas on how to display it using Vue JS 能否请您发送一些有关如何使用Vue JS进行显示的想法

 <div id="main" v-cloak> <div class="col-sm-5"> <p v-for="picture in services.service_picture"></p> <img :src="path + '/images/services/'+ picture" class="img-circle" alt="Services" /> </div> </div> 

 var main = new Vue({ el: "#main", data: { services: [], path: 'https://examplemyapisource.com' }, }); 

 API from https://examplemyapisource.com [ { "service_picture": "18_1516090191.jpg", } ] 

You try here: 您在这里尝试:

<div id="main" v-cloak>
  <div class="col-sm-5">
    <p v-for="picture in services"></p>
    <img :src="path + '/images/services/'+ picture.service_picture" class="img-circle" alt="Services" /> </div>
</div>

归功于黄虹

 <img :src="path+'/images/services/'+services.service_picture" class="img-circle" alt="Services"> 

Note the your v-for only includes the 请注意,您的v-for仅包括

element, therfore you cannot use 'picture' inside the element. 元素,因此您不能在元素内部使用“图片”。

<p v-for="picture in services.service_picture"></p>
<img :src="path + '/images/services/'+ picture" class="img-circle" alt="Services" />

You need to make these changes to get a perfect image. 您需要进行这些更改才能获得完美的图像。 Here you closed the <p> tag before the image.close that <p> tag after image 在这里,您关闭<p>该image.close前标签<p>图像标签后

<div id="main" v-cloak>
   <div class="col-sm-5">
   <p v-for="picture in services">
      <img :src="path + '/images/services/'+ picture.service_picture" class="img-circle" alt="Services" /> </div>
   </p>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM