Images not showing in Vue.js

I have been working on setting up a carousel using bootstrap-vue. It is being generated dynamically through an array containing three objects with keys such as id, caption, text, and image path. The issue I am facing now is that while the caption and text are displaying correctly, the images are not showing up. Despite checking the console for errors and finding none, I am puzzled by this situation. Below you can find my code snippets along with screenshots of the problem.

UPDATE: I have been struggling with this problem for two days now, and any assistance would be greatly appreciated!

Here is the structure of my project

https://i.stack.imgur.com/CHasv.png

This is the code I am using

<template>
  <div>
    <b-carousel
      id="carousel-1"
      v-model="slide"
      :interval="10000"
      controls
      indicators
      background="#ababab"
      style="text-shadow: 1px 1px 2px #333;"
      @sliding-start="onSlideStart"
      @sliding-end="onSlideEnd"
    >
      <b-carousel-slide
        v-for="item in carouselItems"
        :key="item.id"
        :caption="item.caption"
        :text="item.text"
        :style="{ 'background-image': 'url(' + item.image + ')' }"
      ></b-carousel-slide>
    </b-carousel>
  </div>
</template>

<script>

export default {
  data() {
    return {
      carouselItems: [
        {
          id: 1,
          caption: "Memories",
          image: "@/assets/images/Homepage-min.jpg",
          text: "Memories(1)"
        },
        {
          id: 2,
          caption: "Memories",
          image: "@/assets/images/Homepage-min.jpg",
          text: "Memories(2)"
        },
        {
          id: 3,
          caption: "Memories",
          image: "@/assets/images/Homepage-min.jpg",
          text: "Memories(3)"
        }
      ],
      slide: 0,
      sliding: null
    };
  },
  methods: {
    onSlideStart(slide) {
      this.sliding = true;
    },
    onSlideEnd(slide) {
      this.sliding = false;
    }      
  }
};
</script>

Here is a screenshot: https://i.stack.imgur.com/C3bao.png

Update To investigate further, I checked the networks tab to verify if the image paths were correct. Surprisingly, the status code was 304 which implies that they are indeed correct. Can anyone suggest what might be causing this issue?

https://i.stack.imgur.com/WV2oo.png

Update: After removing the style attribute and replacing it with the following code

:img-src="item.image"

After saving the changes and refreshing the page, I noticed an icon indicating that the browser failed to load the images.

https://i.stack.imgur.com/PjAxQ.png

Update Success! I managed to display the images on the carousel-slide successfully. It turns out that using "require" is necessary when dealing with relative image paths. I have updated this section of my code as shown below

data() {
    return {
      carouselItems: [
        {
          id: 1,
          caption: "Memories",
          image: require("@/assets/images/Homepage-min.jpg"),
          text: "Memories(1)"
        },
        {
          id: 2,
          caption: "Memories",
          image: require("@/assets/images/Homepage-min.jpg"),
          text: "Memories(2)"
        },
        {
          id: 3,
          caption: "Memories",
          image: require("@/assets/images/Homepage-min.jpg"),
          text: "Memories(3)"
        }
      ],
      slide: 0,
      sliding: null
    };
  },

Update However, a new challenge emerged - the images do not fit the entire height of the screen in mobile mode. I aim for them to be responsive. Here's a snapshot of my dilemma

Update 7/5/2019 I am still grappling with this issue, so if anyone could provide CSS guidance, I would greatly appreciate it.

https://i.stack.imgur.com/EukSA.png

Answer №1

Consider utilizing img-src="https://xxxxx" instead of modifying the style. Your code should look something like this:

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

Alternatively, you can simply insert an actual img tag within the <b-carousel-slide>:

     <b-carousel-slide>
        <img
          slot="img"
          class="d-block img-fluid w-100"
          width="1024"
          height="480"
          src="https://xxxxxx"
          alt="image slot"
        >
      </b-carousel-slide>

Make sure to verify the 'path' of your images as webpack automatically adds a unique-id to each image which may cause issues in certain scenarios. Ensure that the webpack config is properly functioning with your images.

Answer №2

<b-carousel> doesn't cut off images; instead, it aims to preserve their original aspect ratio (similar to the native Bootstrap V4.x carousel).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to showcase the information in my customized SharePoint Online list through a Web Part Page utilizing AngularJS

<script> //AngularJS Code goes here var appVar = angular.module('listApp', ['ngRoute']); appVar.controller("controller1", function($scope){}); function FetchEmployeeData($scope, EmployeeList){ var reque ...

Load certain database information into memory as Express initializes

Are there any efficient methods for storing data in Express? For instance, I am interested in preloading all API keys from a PostgreSQL database into memory when the server is initialized to avoid having to query the database for each API request. I consi ...

Creating a dropdown menu in Bootstrap 4 using JSON information

I am trying to create a dynamic drop-down menu using an input field with a drop-down button inside a form. Currently, I am attempting to populate the drop-down menu with static JSON data. However, I am encountering issues with getting it to function proper ...

Two separate tables displaying unique AJAX JSON response datasets

As a beginner in javascript, I am facing a challenge. I want to fetch JSON responses from 2 separate AJAX requests and create 2 different tables. Currently, I have successfully achieved this for one JSON response and table. In my HTML, I have the followi ...

Optimizing communication of time data in Laravel and Vue.js using Inertia

Currently, I am encountering an issue while working with Laravel Inertia and Vue.js. The problem arises when the time is transferred between Laravel and Vue.js, as it always converts to UTC automatically, which is not what I want. For instance, if I am u ...

Module for Node.js that handles .ini files where variable names can begin with a number

.ini file: [1] 10X=true [2] 10X=true node.js : var mS = ini.parse(fs.readFileSync(__dirname + '/XXX/MS.ini', 'utf-8')); console.log(mS.1.10X); I am utilizing the ini module in node.js, which can be found at this link: https://www.n ...

Equal size images displayed within cards in Material UI

Is there a way to create a list of Material UI components with images that have uniform height, even if the original images vary in size? I want to make all image heights responsive and consistent across all cards. Any suggestions on how to achieve this? ...

JavaScript: Exploring Content Inside Headers

Using document.body.innerHTML allows you to search within the body of a webpage. Is there an equivalent method for searching within the "Head" section? I've been looking around but so far, I haven't come across any such function. ...

"Utilizing AngulaJS to apply a class to the parent element when a radio button is

I'm wondering how I can assign a class to the parent div of each radio button in a group? You can find the code below and view the corresponding JSFiddle here. Here is the HTML: <div class="bd"> <input type="radio" ng-model="value" val ...

Tips on customizing the CSS responsiveness of your Bootstrap carousel

I have recently installed a Bootstrap theme on my Wordpress site and I am trying to make some CSS adjustments. One issue I am facing is with the carousel. Currently, when I resize the website or view it on a mobile device... The carousel maintains a lar ...

Managing options post initialization in egjs-flicking: A comprehensive guide

In my Vue2 project, I am currently utilizing egjs-flicking. I am looking for a solution to implement different align options based on the screen size (mobile or desktop). Is there a method to accomplish this without having to destroy or reinitialize the ...

I am looking to dynamically add and remove an active link on my sidebar using JavaScript

Looking to create a dynamic website with interactive features like adding and removing active links upon clicking, and smooth transitioning between sections using JavaScript. Feel free to skip over the SVG code. HTML source code <div class="s ...

Unable to access controller using jquery/ajax in CodeIgniter along with a bootstrap template

When loading a page into another, everything seems to be working fine except for the controller loading: The scripts and CSS are being loaded in the default page code, which might be causing the issue. The error message "Failed to load resource: the serve ...

Switching up the content within double curly braces in Vue.js - A guide

Recently, I've been working on building a data table and I've hit a roadblock. I want the columns to be clickable so that I can display the rows in ascending and descending order. When they are displayed in ascending order, I'd like to show ...

Utilizing Fullcalendar 5 in conjunction with Angular: Embedding Components within Events

Recently, my team made the transition from AngularJS to Angular 12. With this change, I upgraded Fullcalendar from version 3 to version 5 and started using the Angular implementation of Fullcalendar: https://fullcalendar.io/docs/angular While navigating t ...

Unsuccessful attempt at aborting an Ajax request

Currently, I have developed a basic live search feature using jQuery ajax to search through a JSON file on the server and display a list of events. The script is programmed to show a list of events that were previously displayed on the page if the search ...

Is it possible that WebdriverIO is unable to retrieve the value for an input

Currently, I am in the process of automating tests specifically for a web application on Safari browser. However, I have encountered some challenges along the way. It appears that webdriverIO is not performing very well with Safari in my environment, which ...

The function cb() was never executed during the installation of @vue/cli

Hey everyone, I'm new to this and currently facing an issue while trying to set up vue cli for frontend development using npm. After running sudo npm install -g @vue/cli, the following output shows up: [18:00 vue]$ sudo npm install -g @vue/cli npm W ...

Utilize the Image URL for training your Tensorflow.js application

I'm currently exploring how to use images sourced from the internet for training my neural network. I am utilizing an Image() object to generate the images and pass them to tensorflow. Despite my understanding that Image() should return a HTMLImageEle ...

Finding the parent directory path within gulp.dest(): A step-by-step guide

I've recently started using Gulp and I'm facing an issue when trying to output my files to their parent directory. This is how my directories are structured: app/page_a/less/a.less app/page_a/css My desired outcome is: app/page_a/less/a.less ...