link2466 link2467 link2468 link2469 link2470 link2471 link2472 link2473 link2474 link2475 link2476 link2477 link2478 link2479 link2480 link2481 link2482 link2483 link2484 link2485 link2486 link2487 link2488 link2489 link2490 link2491 link2492 link2493 link2494 link2495 link2496 link2497 link2498 link2499 link2500 link2501 link2502 link2503 link2504 link2505 link2506 link2507 link2508 link2509 link2510 link2511 link2512 link2513 link2514 link2515 link2516 link2517 link2518 link2519 link2520 link2521 link2522 link2523 link2524 link2525 link2526 link2527 link2528 link2529 link2530 link2531 link2532 link2533 link2534 link2535 link2536 link2537 link2538 link2539 link2540 link2541 link2542 link2543 link2544 link2545 link2546 link2547 link2548 link2549 link2550 link2551 link2552 link2553 link2554 link2555 link2556 link2557 link2558 link2559 link2560 link2561 link2562 link2563 link2564 link2565 link2566 link2567 link2568 link2569 link2570 link2571 link2572 link2573 link2574 link2575 link2576 link2577 link2578 link2579 link2580 link2581 link2582 link2583 link2584 link2585 link2586 link2587 link2588 link2589 link2590 link2591 link2592 link2593 link2594 link2595 link2596 link2597 link2598 link2599 link2600 link2601 link2602

[Vue.js] Cannot render images dynamically to carousel Vuejs

I’ve set up a carousel using bootstrap-vue. I used a for loop and an array of objects to dynamically create the component. In each of the slide, I will include a text as well as a background image. I was able to render the texts dynamically. However, the background image only appeared at the first slide. For subsequent slides, the image will not be rendered anymore. What seems to be the problem? Below are my codes and a screenshot of the result

Update: when still not able to get this to work. Can anyone help me?

<template>
<div>
<b-carousel
id=”carousel-1”
v-model=”slide”
:interval=”4000”
controls
indicators
background=”#ababab”
style=”text-shadow: 1px 1px 2px #333;”
@sliding-start=”onSlideStart”
@sliding-end=”onSlideEnd”
\>
<!– Text slides with image –>
<b-carousel-slide
v-for=”item in carouselItems”
:key=”item.id”
:text=”item.text”
:style=”{ ‘background-image’ : ‘url(\‘’ + item.image + ‘\‘)’ }”
\></b-carousel-slide>
</b-carousel>
<ProductList/>
</div>
</template>

<script>
// 1. Loading images asychronously later on from S3
// https://stackoverflow.com/questions/50659676/how-to-load-image-src-url-in-vuejs-asyncronously
import ProductList from “@/components/product/ProductList.vue”;

export default {
components: {
ProductList
},
data() {
return {
carouselItems: [
{
id: 1,
image: “https://source.unsplash.com/LAaSoL0LrYs/1920x1080",
text: “Nulla vitae elit libero, a pharetra augue mollis interdum. (1)”
},
{
id: 2,
image: “https://source.unsplash.com/LAaSoL0LrYs/1920x1080",
text: “Nulla vitae elit libero, a pharetra augue mollis interdum. (2)”
},
{
id: 3,
image: “https://source.unsplash.com/LAaSoL0LrYs/1920x1080",
text: “Nulla vitae elit libero, a pharetra augue mollis interdum. (3)”
}
],
slide: 0,
sliding: null
};
},
methods: {
onSlideStart(slide) {
this.sliding = true;
},
onSlideEnd(slide) {
this.sliding = false;
}
}
};
</script>

<style scoped>
.carousel-item {
height: 100vh;
min-height: 350px;
background: no-repeat center center scroll;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>

Carousel when it was first rendered

Subsequent slide not display image

Returning back to slide 1 and the background image is gone

Solution :

As you use bootstrap-vue.js library, you can use “caption” attribute instead of “text” and “img-src” instead of style:background. Because b-carousel-slide component override style tag.

<b-carousel-slide
v-for=”item in carouselItems”
:key=”item.id”
:caption=”item.text”
:img-src=”item.image”
\></b-carousel-slide>

If you want to have a custom style for the crousal you can set an additional class attr to the tag like:

<b-carousel-slide
class=”MyCustomClass”
….
\></b-carousel-slide>
<style>
.MyCustomClass {
width: 100%;
object-fit: cover;
}
</style>

But pay attention that the carousal you are using is either responsive and also full-width. I think the problem is something else.