为什么在img,vuejs中使用v-for时轮播无法正常工作?

问题描述 投票:0回答:1

我当前正在使用以下库:https://www.npmjs.com/package/vue-owl-carousel

事实证明,当在轮播中的img中使用v-for时,轮播无法正常工作。

这种方式不起作用:

<carousel
    :autoplay="true"
    :loop="true"
    :center="true"
    :nav="false"
    :margin="5"
>
  <img
    v-for="item in detIncidente.fotos"
    :key="item.fecha"
    :src="item.path"
    width="446"
    height="446"
    @click="showSingle(item.path)"
   />
</carousel>

通过这种方式,如果它对我来说正常工作:

    <carousel
      :autoplay="true"
      :loop="true"
      :center="true"
      :nav="false"
      :margin="5"
    >
       <img width="446" height="669" src="https://placeimg.com/200/200/any?3" />
       <img width="446" height="669" src="https://placeimg.com/200/200/any?4" />
       <img width="446" height="669" src="https://placeimg.com/200/200/any?2" />
       <img width="446" height="669" src="https://placeimg.com/200/200/any?3" />
</carousel>
vue.js owl-carousel
1个回答
0
投票

如果动态加载图像,则轮播组件不会等到数据加载完毕。

您可以尝试添加v-if

v-if="detIncidente && detIncidente.fotos && detIncidente.fotos.length"

完整代码

<carousel
    v-if="detIncidente && detIncidente.fotos && detIncidente.fotos.length"
    :autoplay="true"
    :loop="true"
    :center="true"
    :nav="false"
    :margin="5"
>
  <img
    v-for="item in detIncidente.fotos"
    :key="item.fecha"
    :src="item.path"
    width="446"
    height="446"
    @click="showSingle(item.path)"
   />
</carousel>
© www.soinside.com 2019 - 2024. All rights reserved.