【问题标题】:Showing multiple images in Vue3-carousel在 Vue3-carousel 中显示多个图像
【发布时间】:2021-09-12 12:22:53
【问题描述】:

我在网上到处搜索答案,但无济于事。

请好心人向我这个新手解释一下,我如何获得使用Vue3-carousel 显示的三个单独的图像?

我查看了 Vue3-carousel 文档,但如果有解决方案,我看不到它。

<template>
  <section class="productOverview">
    <Carousel :itemsToShow="3" :wrapAround="true">
      <Slide v-for="slide in 3" :key="slide">
        <div class="carousel__item">{{ slide }}</div>
      </Slide>
    </Carousel>
  </section>
</template>

我假设魔法发生在脚本区域的某个地方...

<script>
 import { defineComponent } from "vue";
 import { Carousel, Slide } from "vue3-carousel";
 import "vue3-carousel/dist/carousel.css";
    
 export default defineComponent({
  name: "Autoplay",
  components: {
    Carousel,
    Slide,
  },
});
</script>

提前致谢。

【问题讨论】:

    标签: javascript vue.js carousel vue3-carousel


    【解决方案1】:

    尝试使用您的图片网址创建数据对象:

    export default defineComponent({
      name: "Autoplay",
      components: {
        Carousel,
        Slide,
      },
      data() {
        return {
          images: [{id: 1,url:'img1url'}, {id: 2,url:'img2url'}, {id: 3,url:'img3url'}]
        }
      }
    

    然后我通过图像模板循环

     <Slide v-for="(image, index) in images" :key="image.id">
        <img :src="getImage(image.url)" />
        <button v-if="slidesCount > 1" @click="deleteImage(index)">x</button>
      </Slide>
    

    图片方法:

    methods: {
      getImage(imagePath) {
        return require(imagePath);
      }
    }
    

    【讨论】:

    • 不客气 :) 如果您的图片在 src -> assets 文件夹中,请尝试使用 @/assets/img1.png
    • 我想我已经非常接近了,但目前还没有图像,即使图像路径与您建议的相同......嗯......
    • 现在检查队友,也许你需要方法的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2013-03-03
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 2015-03-03
    相关资源
    最近更新 更多