【问题标题】:Carousel bootstrap with vue js component带有 vue js 组件的轮播引导程序
【发布时间】:2022-01-19 00:02:36
【问题描述】:

目前我正在使用带有指示器 GetBootstrap Carousel With indicators 的 Carousel 创建一个组件 我正在一个 vue 组件中实现此代码,例如:

<template>
    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
            <div v-for="(image, index) in images" :key="index">
                <li data-target="#carouselExampleIndicators" :data-slide-to="index" :class=" index === 0? 'active' : '' "></li>
            </div>
        </ol>
        <div class="carousel-inner">
            <div v-for="(image, index) in images" :key="index">
                <div :class=" index === 0? 'carousel-item active' : 'carousel-item' ">
                    <img class="d-block w-100" :src="image.path" :alt="image.name">
                </div>
            </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
</template>

<script>
    export default {
        props: ["app_route"],
        data() {
            return {
                images: [],
            };
        },
        mounted: function() {
            this.getItemsSlider();
        },
        methods: {
            getItemsSlider() {
                axios
                    .get(this.app_route + "/admin/slider/list", {
                    })
                    .then((response) => {
                        //console.log("response: ", response.data);
                        this.images = response.data;
                    });
            },
        }
    };
</script>

目前第一张图片正在显示,但其他图片没有显示,滑块也不工作。

为什么?我做错了什么?

这里是代码codesandbox

【问题讨论】:

    标签: vue.js bootstrap-4 slider carousel


    【解决方案1】:

    根据the documentation,必须严格嵌套元素.carousel-inner &gt; .carousel-item

    你应该试试这个:

    <div class="carousel-inner">
      <div v-for="(image, index) in images" :key="index" :class="index === 0 ? 'carousel-item active' : 'carousel-item'">
          <img class="d-block w-100" :src="image" :alt="image.name" />
      </div>
    </div>
    

    【讨论】:

    • 是的!是工作!!!非常感谢!
    猜你喜欢
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    相关资源
    最近更新 更多