You are currently experiencing an error with the transpilation of the image located at @/src/assets/images/1.jpg in Vue

**I encountered an error when trying to transpile the image file '1.jpg' in Vue. I'm looping through the static array in the App component and the src is correctly specified. I am using the require Vue method for this operation.

Link to code sandbox **

// APP

<template>
  <v-carousel :carousel_data="sliderItems" />
</template>
<script>
import vCarousel from "./components/v-carousel.vue";
export default {
  name: "App",
  data() {
    return {
      sliderItems: [
        { id: 1, name: "img1", img: "1.jpg" },
        { id: 2, name: "img2", img: "2.jpg" },
        { id: 3, name: "img3", img: "3.jpg" },
      ],
    };
  },
  components: {
    vCarousel,
  },
};
</script>

// Parent

<template>
  <div class="container">
    <div class="v-carousel">
      <v-carousel-item
        v-for="item in carousel_data"
        :key="item.id"
        :item_data="item"
      />
    </div>
  </div>
</template>
<script>
import vCarouselItem from "./v-carousel-item.vue";
export default {
  components: {
    vCarouselItem,
  },
  props: {
    carousel_data: {
      type: Array,
      default: () => [],
    },
  },
};
</script>


// Child 

<template>
  <div class="v-carousel-item">
    <img :src="require(`../assets/images/` + item_data.img)" alt="" />
  </div>
</template>
<script>
export default {
  props: {
    item_data: {
      type: Object,
      default: () => {},
    },
  },
};
</script>

Answer №1

To ensure that the images are loaded beforehand.

export default {
  name: "App",
  data() {
    return {
      sliderItems: [
        { id: 1, name: "img1", img: require("@/assets/images/1.jpg") },
        { id: 2, name: "img2", img: require("@/assets/images/2.jpg") },
        { id: 3, name: "img3", img: require("@/assets/images/3.jpg") },
      ],
    };
  },

Next, make sure to update the carousel item component.

  <div class="v-carousel-item">
    <img :src="item_data.img" alt="" />
  </div>

For a demonstration, visit: https://codesandbox.io/s/little-bush-ino5zc?file=/src/components/v-carousel-item.vue:11-91

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

How can I use `app.js` in Zendesk to connect to an external API using the complete URL

As someone new to developing Zendesk apps, I've been following the step-by-step guide available here. To Summarize I'm facing an issue with passing external API URLs to the AJAX call syntax within Zendesk's app.js file. You can find my sim ...

Google Chrome is currently misreporting image dimensions when they are loading

Chrome is inaccurately displaying width and height values for images either during or shortly after loading. This code example utilizes JQuery: <img id='image01' alt='picture that is 145x134' src='/images/picture.jpg' /> ...

InnerHTML syntax for creating the button in the cell is not functioning properly with the HTML onclick event

I'm facing an issue with my code where I am trying to insert a button into a table cell. The button has an action assigned to it using the onclick attribute. However, no matter how I try to use single quotes with or without backslashes in the syntax o ...

Invalid Resize Argument Causes Background to Not Appear on IE Browser

I have encountered a problem where the background (BG) image is not appearing in Internet Explorer (IE). I am struggling to find a solution for this issue. BG Problem Below is the code snippet showing how I implemented the background image. I have used a ...

"How to ensure consistent styling for all buttons, including dynamically created ones, in an application by utilizing the jQuery button widget without the need for repetitive calls to

Hello everyone, I am a newcomer to stack overflow and I have a question to ask. Please excuse any errors in my query. I have searched for an answer but have not been successful in finding one so far. Let's say I have a webpage where I am using the jQ ...

How can I notify an error in CoffeeScript/JavaScript when a parameter is not provided?

Initially, I believed that my code was clever for accomplishing this task: someFunction = (arg1, arg2, arg3) -> if _.some(arguments, (a) -> a is undefined) throw new Error "undefined parameter" My goal was to throw an error if any of the para ...

The Error message "Property 'data' is not present in Type <void> | AxiosHttpResponse<any>" is indicating that the data property is missing on

When I fetch data for a specific user, I have a promise that I use to setState. Below is the implementation: getUserUsername = (): string => { const { match } = this.props; return match.params.username; }; onFetchUser = () => getUse ...

Change the clear color in Three.js for GPU ping-ponging operations

Currently working on a project involving GPU ping-ponging in Three.js, but encountering an unusual issue. When I try to set the clear color for the renderer, it seems to override the output of the fragment shader responsible for rendering. Oddly enough, s ...

Tips on utilizing useStyle with ReactJS Material UI?

Is there a way to utilize a custom CSS file in the useStyle function of Material UI? I have created a separate useStyle file and would like to incorporate its styles. Can someone explain how this can be accomplished? input[type="checkbox"], inp ...

Seeking assistance with Shopify - Enhancing User Experience with Javascript Cookies

Is there a way to adjust the settings of how long Shopify stores cookies on your computer for? Currently, it retains cart information for two weeks. Any suggestions on how to modify this? I am considering two possibilities: 1) Making shopping members-only ...

Tips for updating React context provider state when a button is clicked

WebContext.js import React, { createContext, Component } from 'react'; export const WebContext = createContext(); class WebContextProvider extends Component { state = { inputAmount: 1, }; render() { return <WebC ...

transferring information between controllers and saving it persistently in AngularJS even after refreshing the

What is the best way to share data (Object) between controllers with different routes and prevent data loss after a page reload? I have an object that I need to use to prefill form values on my destination page based on choices made on my source page. S ...

Rotate a numpy array containing coordinates by an angle of 45 degrees

I have an array "A" containing x and y coordinates arranged in a 2x32 numpy format, and I am looking to rotate it by 45 degrees around the center point. x = np.tile([1,2,3,4],8) y = np.repeat([1,2,3,4,5,6,7,8],4) A = np.vstack((x,y)) # This is just a simpl ...

delay of Paypal API disbursement for transactions with a range of money values

After browsing through various resources such as this link, that link, and another one on the PayPal developer website, I attempted to implement a payment processing system that allows users to approve a preset amount of money. Similar to services like Ube ...

Does binary search maintain its usual efficiency?

Does binary searching remain efficient and effective if an array inherits from an object? ...

Looping through numbers from 0 to 100, calculating and displaying the total sum of even numbers and odd numbers separately in an array

I am attempting to iterate through numbers from 0 to 100 and calculate the sum of even numbers and odd numbers in an array format, for example [2550, 2500]. let total = 0; for(let num = 0; num <= 100; num++) { total = total + num; } console.log(Arr ...

Ensuring secure JSON parsing in Node.js when encountering errors

When working with node/express and trying to extract JSON from request headers, I want to make sure it's done safely. If the JSON is not valid for some reason, I don't want it to throw a syntax error - instead, I prefer it to just return false or ...

Uninstalling NPM License Checker version

Utilizing the npm license checker tool found at https://www.npmjs.com/package/license-checker The configuration in license-format.json for the customPath is as follows: { "name": "", "version": false, "description&quo ...

What is the best way to store query responses in global.arrays without overwriting the existing values stored within the array elements of global.arrays?

QUESTION: I am struggling to efficiently assign results of MongoDB queries to global arrays. I attempted to store references to the global arrays in an array so that I could easily assign query results to all of them using a for loop. However, this appro ...

Retrieving the value of an inner div upon clicking the outer div

I currently have a collection of button divs, each containing distinct information: <div class="button"> <div id="first"> Johny </div> <div id="second"> Dog </div> <div id="third"> Pasta & ...