Uploading images from your personal computer to the Carousel component in Vuetify

When trying to add a picture to a Carousel from my own computer by using the URL link, the pictures do not show up. How can I successfully add images stored on my computer to the Carousel?

Below is the code snippet:

<template>
<div class="caro">

 <v-carousel >
  <v-carousel-item
    v-for="(item,i) in items"
    :key="i"
    :src="item.src"
  >

    <div class="text-xs-center">
    </div>

  </v-carousel-item>
 </v-carousel>
</div>
</template>

<script>
export default {
 data () {
  return {
    items: [
      {
        id: 'rack', src: 'https://logisticpackaging.com/CrXBdba4vG7B2k/wPHm6Sft56fw2V/wp-content/uploads/2015/06/pcb-racking-system5.jpg', title:'Rack Section'
      },
      {
        id: 'subrack', src: '../assets/Parts.jpg' , title: 'Subrack Section'
      },

      {
        id: 'parts', src: '../Hasan.jpg' , title: 'Parts Section'
      },
      {
        id: 'admin', src: 'https://d15shllkswkct0.cloudfront.net/wp-content/blogs.dir/1/files/2013/04/Transactional-Database.jpg' , title: 'Database Section'
      }
    ]
  }
}

In this scenario, the "rack" and "admin" sections show pictures because they are sourced from the internet. However, the "parts" and "subrack" sections do not display images because I am attempting to use pictures saved on my own computer.

Answer №1

When developing, are you using npm in dev mode or Build? I typically create a folder named public to store all my images, SVGs, and other files because webpack incorporates this folder with the Vue code.

In my source code, I reference these files like this: src="img/brand/logo.svg"

If you are not utilizing webpack and a vue build template, it is advisable to keep your images within the public folder. This folder is easily transferable and will likely be included by webpack, so all files can be uploaded to the dist folder.

Answer №2

When attempting to display two photos in the carousel, ensure they are coming from the same source. Verify that the photo extension in the code matches the actual extension in the source folder to prevent any rendering issues.

Answer №3

When working with Vue, the Vue loader will automatically handle converting relative paths to required functions. However, this functionality does not apply to custom components. To resolve this issue, you can utilize the require method. By modifying the format of the items array as shown below, you can successfully address the problem:

<script>
export default {
 data () {
  return {
   items: [
      {
        id: 'subrack', src:  require('../assets/Parts.jpg') , title: 'Subrack Section'
      },

      {
        id: 'parts', src:require( '../Hasan.jpg'), title: 'Parts Section'
      },
    ]
  }
}

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

The specified function 'isFakeTouchstartFromScreenReader' could not be located within the '@angular/cdk/a11y' library

I encountered the following errors unexpectedly while working on my Angular 11 project: Error: ./node_modules/@angular/material/fesm2015/core.js 1091:45-77 "export 'isFakeTouchstartFromScreenReader' was not found in '@angular/cdk/a11y&a ...

Pnotify encounters a glitch where the buttons are not displayed when utilized with jquery

Using pnotify with jQuery and Bootstrap3, I am facing an issue where the buttons do not appear. In order to address this problem, I have ensured that both pnotify.custom.min.css and pnotify.custom.min.js files are included in the header of the application ...

dynamically open ngx-bootstrap accordion panels

I implemented the ngx-bootstrap accordion feature to display a list of blog posts. Below is the template structure: <accordion id="blog-list"> <accordion-group *ngFor="let post of posts; let first = first;" [isOpen]="first" id="post-{{post.i ...

Failure to execute Ajax request when searching for a query

My personal GitHub profile viewer React application allows you to search for a profile by username. By default, my own GitHub username is provided on the landing page. However, when trying to search for another user, my ajax call is not functioning properl ...

Ensure that the JavaScript file is fully loaded and that the JavaScript function has been properly initiated prior to executing any additional

Having an issue with a tracking code not working properly as it is called before a required JS script and function is loaded. The situation is as follows: Upon successful form submission (CF7 on WordPress), the following function is immediately called. ...

Utilize Jquery to access and manipulate elements within an object

Currently, I have an array of objects that I am looping through to access all the objects stored within it. However, my goal is to obtain the elements of each object individually. Even though I attempted to manage this using the following code, the output ...

Experiencing a websocket issue despite not incorporating websocket functionality in the code

Whenever I attempt to run npm run dev, I encounter a websocket error. I'm part of a team with WSL and Mac users, and the repository runs smoothly for everyone else except me. I'm puzzled as to why I'm the only one facing this issue while try ...

What is the TypeScript equivalent of the Java interface.class?

Can you write a Java code in TypeScript that achieves the same functionality as the code below: Class<?> meta = Object.class; and meta = Processor.class; // Processor is an interface In TypeScript, what would be the equivalent of .class? Specifica ...

Issue with Angular UI-Router: Unexpected failure to load template not requested by user

Click here to view the Plunker code related to the issue described below Full link: http://plnkr.co/edit/Bz3Qhf1eDuFrnKI0qnUo?p=preview Exploring the functionalities of two components from the AngularUI suite - UI-Router and UI-Bootstrap. UI-Router manag ...

Next.js encountered an API resolution issue while uploading a file, resulting in no response being

Even though my code is functioning properly, a warning appears in the console: The API call was resolved without sending any response for /api/image-upload This particular endpoint is responsible for uploading an image to Digital Ocean's object sto ...

Sending a list of data to a child component in Vue

After reviewing various answers on here, such as this one, it seems like passing imported JSON data from the parent to the child component should work. The import and looping through data functions perfectly if I do it all in the parent with a v-for: < ...

Can hash routes be defined in next.js?

Previously, I created a modal component using <HashRouter> in react-router where the modal would become active or inactive based on the hash url. For example, the modal is inactive when the url is /route, but becomes active when the url is /route#m ...

Having trouble with the initial slides not appearing when utilizing multiple JavaScript carousels

I have encountered an issue with my carousels where the first slides are not displaying properly. I don't have much coding experience and have pieced together some code snippets from various sources, primarily w3schools. The page does not require any ...

How can I customize a default button in HTML to hide the selected option from the dropdown menu?

Hey there! I'm currently working on a website that needs to be bilingual, with Spanish as the default language. I want to include a dropdown button that allows users to translate the content into English. Here's what I've tried so far: ...

Is there a way to update the styling of specific sections of an input field as the user enters text in React?

Just like in most markdown editors, I am looking to enable the ability to modify parts of an input field as the user enters text. For instance: When the user types "_above_", as soon as the second underscore is typed, the text should be styled accordingly ...

Adapting JavaScript functions from IE to work on Firefox and Chrome: A comprehensive guide

I have encountered an issue with a function that retrieves the selected text range within a contenteditable div. While it works perfectly fine in Internet Explorer, it doesn't seem to work in Firefox and Chrome. Could someone kindly provide guidance ...

Discovering the identical element within the ajax response

The following section is being targeted: var obj = $(this).parent().find('a'); // $(this) is a <UL> inside a <DIV>, but there can be multiple DIV>ULs on the page After that, I retrieve some HTML using $.ajax(). This HTML corres ...

Navigating JSON encoded strings with jQuery

Currently, I am utilizing Django to create JSON encoded objects that are then retrieved using jQuery.getJSON(). The standard simplejson encoder encodes strings following the JSON "standard". For example, any string containing a '/' is converted t ...

Programmatically Adjusting Width of Bootstrap Modal

I am looking for a way to dynamically change the width of a modal using either jQuery or vanilla JavaScript. Below is the code I have: <div class="modal fade" id="modal-popup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div cl ...

"Guidelines for implementing a post-login redirection to the homepage in React with the latest version of react-router (v

I am facing an issue where I am unable to redirect to the Home Page when I click the "Login" button during my React studies. Despite trying all possible methods for redirects, none of them seem to work. The function that is executed when I click the "logi ...