带有 vue js 组件的轮播 bootstrap
Carousel bootstrap with vue js component
目前我正在使用带指示器的 Carousel 创建一个组件 GetBootstrap Carousel With indicators
我在一个 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
根据the documentation,元素必须严格嵌套.carousel-inner > .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>
目前我正在使用带指示器的 Carousel 创建一个组件 GetBootstrap Carousel With indicators 我在一个 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
根据the documentation,元素必须严格嵌套.carousel-inner > .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>