What is the best method for properly inserting images into a Vue Carousel 3D slider?

I'm currently exploring the Vue Carousel 3D documentation and I am having trouble displaying a single image on each slide. Let me elaborate: I aim to create a slider similar to the one shown in the Controls Customized example in the documentation.

This is the code snippet that I came across:

new Vue({
  el: '#example',
  data: {
    slides: 8
  },
  components: {
    'carousel-3d': window['carousel-3d'].Carousel3d,
    'slide': window['carousel-3d'].Slide
  }
})
<div id="example">
  <carousel-3d :controls-visible="true" :controls-prev-html="'❬ '" :controls-next-html="'❭'" :controls-width="30" :controls-height="60" :clickable="false">
    <slide v-for="(slide, i) in slides" :index="i">
      <figure>
        <img src="https://placehold.it/360x270">
      </figure>
    </slide>
  </carousel-3d>
</div>

Similar to the sample

However, upon trying to implement this code as it is displayed in the example, I ended up with sliders showing duplicate images. I also couldn't grasp the purpose of using: index = "i". Initially, I thought it was specifying image priorities, but this assumption proved to be incorrect.

<div id="example">
  <carousel-3d :controls-visible="true" :controls-prev-html="'&#10092; '" :controls-next-html="'&#10093;'" :controls-width="30" :controls-height="60" :clickable="false">
    <slide v-for="(slide, i) in slides" :index="i">
      <figure>
        <img src="/img/sliders/1.jpg">
      </figure>
    </slide>
    <slide v-for="(slide, i) in slides" :index="i">
      <figure>
        <img src="/img/sliders/2.jpg">
      </figure>
    </slide>
    <slide v-for="(slide, i) in slides" :index="i">
      <figure>
        <img src="/img/sliders/3.jpg">
      </figure>
    </slide>
    <slide v-for="(slide, i) in slides" :index="i">
      <figure>
        <img src="/img/sliders/4.jpg">
      </figure>
    </slide>
    (...more image slides here...)
  </carousel-3d>
</div>

Example Layout

My Outcome

I even attempted using multiple figure tags within the slider tag, encapsulating different pictures in each figure, but that didn't resolve the issue either. Can someone provide insights on this matter, please? The website link:

Answer №1

The primary function of utilizing v-for is to iterate through specific bound data, so incorporating multiple instances of v-for would contradict this purpose. Instead, it is recommended to convert slides into an array structure. For instance, create an array composed of objects that contain relevant image data:

slides: [
   { id: 1, src: '/img/sliders/1.jpg' },
   { id: 2, src: '/img/sliders/2.jpg' },
   { id: 3, src: '/img/sliders/3.jpg' },
   { id: 4, src: '/img/sliders/4.jpg' },
   { id: 5, src: '/img/sliders/5.jpg' },
   { id: 6, src: '/img/sliders/6.jpg' },
   { id: 7, src: '/img/sliders/7.jpg' },
]

One potential approach involves utilizing an array of objects with properties such as id and src. Alternatively, you may opt for an array solely consisting of src strings.

Subsequently, these items can be displayed efficiently by employing a solitary v-for:

<slide v-for="(slide, i) in slides" :index="i">
   <figure>
      <img :src="slide.src">
   </figure>
</slide>

The index attribute functions as a prop within the component, referencing the current index value during the iteration process.

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

Is NextJS Route Handler in Version 13 Really Secure?

Within my forthcoming NextJS 13 web application, I am in the process of integrating an API through route handlers to facilitate functions like user registration and login procedures. Is it considered safe when transmitting sensitive data like a user's ...

Utilizing AngularJS for enhanced data management in DataTables with a customized

I am currently working with AngularJs+DataTable library and I have a specific need to create a custom control that can utilize the exact search function from DataTable, but with a customized user interface. However, when using the search() method, it retur ...

What is the best way to handle images overflowing a div

I am currently working on creating a carousel using React, where the content images are aligned horizontally. If I have 3 image tags within a div with a width of 1200px, how can I effectively control these images to ensure they fit within the container div ...

How to Exclude ress.css in Vuetify.js

How can I prevent ress.css from conflicting with Bootstrap and my custom styles in Vuetify? I attempted to remove it from the Vuetify directory within node_modules, but that did not resolve the issue. ...

Seeking to develop a unique domain-specific language tailored for generating HTML code

I have a vision to develop my own personalized domain-specific language that generates HTML. Essentially, I aim to design quizzes using my custom markup language and later have it transformed into HTML format. For instance: > What is your favorite col ...

The TypeError thrown by Mongo .updateMany() indicates that the property 'updateMany' of the object is not a valid function

Currently, I have a collection named users, which contains the following documents: Document 1: { "_id": { "$oid": "5934fd84d6ba4c241259bed1" }, "first_name": "Joe", "last_name": "Smith", "username": "jsmith", "email": "&l ...

Arranging HTML Lists in Perfect Order

I am working with an HTML list that contains links styled as background images rather than text. The container is 200px tall and I would like the links to be centered inline within the container. Usually, I would use line-height:200px; for text to achieve ...

The AngularJs 2 framework encountered an issue with booting up after attempting to combine all TypeScript files into a single JavaScript file

I am currently utilizing Angular 2 with TypeScript (V-1.8) in my project setup. I have configured my tsconfig to output the code into a single .js file. This single.js file includes the necessary code to bootstrap the application, as the boot.ts file is al ...

Why is my code executing twice rather than just once?

` import './App.css'; import ArrayState from './components/ArrayState'; import FetchApi from './components/FetchAPI/FetchApi'; import Login from './components/Login'; import Useeffect2 from './components/Use ...

Tips for successfully sending an API request using tRPC and NextJS without encountering an error related to invalid hook calls

I am encountering an issue while attempting to send user input data to my tRPC API. Every time I try to send my query, I receive an error stating that React Hooks can only be used inside a function component. It seems that I cannot call tRPC's useQuer ...

Issues with React Router functionality on a live production site are causing complications

I recently created an Amazon-clone UI using create-react-app, but it only displays dummy data. The issue arises after deploying it to Vercel - the routing does not function as expected. When clicking on links, a blank page appears with correct URL paramete ...

Substitute a single occurrence of the dollar sign with an HTML tag

I have been attempting to insert an HTML tag into a price on my e-commerce website. Specifically, I am looking to add a tag between the "$" and the numerical value (e.g. $5.00), but I am unable to locate the core file where I can place the code between the ...

What is the best way to align div elements in HTML5?

I've spent countless hours trying to properly display and align multiple divs. Despite extensive research, I just can't seem to get it right. What I'm aiming for is to have the title of a section in the top left corner, an info box to the l ...

How to resolve a Cross-Origin Resource Sharing (CORS) error when trying to access a local JSON file

Currently, I am attempting to use vanilla JS AJAX request in order to retrieve a JSON string from a locally stored JSON file. My main objective is to accomplish this without relying on JQuery. The code snippet below was inspired by this answer. Despite my ...

Scroll bar displayed on a non-editable text box

The TextArea is currently set to readonly mode using "ng-readonly," which is causing the scrollbar-thumb not to appear. It's important to note that I am not utilizing webkit in this scenario. Below is the HTML code being used: <textarea dataitemfq ...

Employing buffers and streams for data transmission

I am in need of a node.js program that can effectively handle a large JSON dataset with thousands of records. Specifically, I require a script that can extract only the "name" key from each record and transfer it to another file using streams. If there ar ...

Auto-fit HTML Webpage Resizer Simplified

Just finished my very first jQuery project, a simple full-width slider. I've been focusing on HTML & CSS and currently working with C#. The problem is that I don't want the page to be scrollable; I want it to autofit to the webpage. Imagine ope ...

Tips for reducing image file size using ImageMinimizerWebpackPlugin in Next.js (webpack 5)

When attempting to use this plugin for image compression, I am encountering an issue where the build process completes successfully, but the images remain uncompressed. As a beginner with webpack, I'm unsure of what might be causing this problem. Cou ...

Converting a string to a date type within a dynamically generated mat-table

I am working on a mat-table that shows columns for Date, Before Time Period, and After Time Period. Here is the HTML code for it: <ng-container matColumnDef="{{ column }}" *ngFor="let column of columnsToDisplay" > ...

Tips for using Jquery to round up currency values

Is there a way to round up various currencies using jQuery? I have a specific requirement: 10.30 → 10 //Round down if below .5 10.60 → 11 //Round up if after .5 849.95 → 850 1,022.20 → 1022 ...