Vue-incredible swiper, a pair of components swipe using buttons adjacent to one another

I am currently using vue-awesome-swiper and encountering an issue. The swipers on my page have buttons (prev slide, next slide) for navigating through slides. However, when I include two swipers on the same page, the buttons of one swiper end up affecting the other. This means that when I try to swipe to the next slide in the first swiper, the second swiper also moves to the next slide involuntarily. Below is a snippet of my component code:

    <template>
  <div class="container">
      <div class="row">
          <div class="col-xs-12">
            <div class='mobSwip'>
              <div class="swiper-container" id="quick-view-slider">
                <swiper :options="swiperOption">
                  <swiper-slide v-for="screen in screens" :key="screen.key"><img v-bind:src="`https://admin.springsapps.com${screen.url}`"/></swiper-slide>
                  <swiper-slide v-if="!screens"><img src="@/assets/images/quick-view-1.png"/></swiper-slide>
                </swiper>
              </div>
              <!-- <div class="swiper-pagination" slot="pagination"></div> -->
              <div class="swiper-button-next"><span class="icon-play"></span></div>
              <div class="swiper-button-prev"><span class="icon-play-flip"></span></div>
              <!-- <button @click="swipeNext">next</button> -->
            </div>
            </div>
          </div>
        </div>
</template>

<script>
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'

  export default {
    props: {
      screens: {
        type: Array,
        required: false
      }
    },
    data: function () {
      return {
        swiperOption: {
          slidesPerView: 5,
          spaceBetween: 30,
          centeredSlides: true,
          // pagination: {
          //   el: '.swiper-pagination',
          //   clickable: true
          // },
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev'
            // nextEl: this.$el.querySelector('.swiper-button-next'),
            // prevEl: this.$el.querySelector('.swiper-button-prev')
          }
        },
      }
    },
    components: {
      swiper,
      swiperSlide
    }
  }
</script>

<style scoped>
  .swiper-slide {
    width: 60%;
  }
  .swiper-slide:nth-child(2n) {
      width: 40%;
  }
  .swiper-slide:nth-child(3n) {
      width: 20%;
  }
</style>

I've attempted various methods such as using queryselectors, getting button classes by refs, and following the official documentation's methods for swiping, but nothing seems to work. The only way the buttons seem to function properly is when I define them by class in the data object as shown in my code... How can I ensure that my buttons are independent and operate accurately?

Answer №1

After troubleshooting my Nuxt.js/SSR project, here is the solution that worked for me:

1) I separated both swipers into different components (it may or may not be necessary)

2) I included id attributes in the button's divs:

<div id="button-next-relacionados" class="swiper-button-next swiper-button-white"></div>
<div id="button-next-relacionados" class="swiper-button-next swiper-button-white"></div>

3) Instead of using the swiper-button-prev and swiper-button-next classes in the swiper options object, I referenced the new ids:

swiperOption: {
        direction: 'horizontal',
        slidesPerView: 4,
        spaceBetween: 6,
        navigation: {
          nextEl: '#button-next-relacionados',
          prevEl: '#button-prev-relacionados'
        },

Answer №2

My method involves the following code snippet:

this.$refs.carousel.carouselInstance.autoplay()

Answer №3

The issue has been resolved! To achieve this, query the ref on swiper and implement

this.$refs.mobileScreensSwiper.swiper.slideNext()

as a function

Answer №4

 pagination: {
      el: '.swiper-pagination-service',
      clickable: true,
    },

Encountering the same problem, I discovered that setting a unique identifier for pagination is the solution

When Vue-awesome-swiper interacts with the DOM, it relies on matching class names to function properly; having the same class name can cause detection issues with sliders

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

Why isn't the ajax table showing up in my HTML?

I am facing an issue while trying to run an application that involves AngularJS, Ajax, and a Java Controller returning JSON. Despite my efforts, the table is not displaying in the HTML. I am new to working with Ajax and AngularJS, and need assistance troub ...

Creating a versatile JavaScript library that is compatible with various platforms such as browsers, NodeJS, and single page applications like React

My question is: Is it possible to convert a basic file into a versatile library that can be utilized with Browsers (via script tag), Node JS, and Single Page Applications using a single codebase? In the past, I have primarily used existing libraries witho ...

Definition of union types in JavaScript using Typescript

Looking for assistance in creating a d.ts file for the union-type library found at https://github.com/paldepind/union-type Consider the following union type: let Maybe = Type({ Nothing: [] , Just: [Number] }) I am interested in setting up compi ...

Incorporating an HTML/Javascript game into a reactJS website: A step-by-step

After developing a game using plain javascript and HTML along with a few JS libraries, I find myself inquiring about the process of integrating this game into my ReactJS website. Typically, the game is initiated by opening the index.html file located with ...

Positioning a div on the right side of its parent div

Hi there! I'm currently working on a small navbar that has two sections: the left section with an arrow icon and the right section with two icons - an envelope and an exclamation triangle. I've been trying to position the right section in the top ...

What could be causing my data to appear as undefined or empty? I am using jQuery.post() to send data from JavaScript to PHP

Issue: I am encountering a problem while sending data to my PHP using jQuery's $.post method. The variable data appears to be undefined for some reason. Let me describe the structure of my code... 1. Here is the button with an onClick function: $dat ...

Managing the rendering of charts in Angular with Directives

I'm in the process of creating an admin page with multiple elements, each revealing more information when clicked - specifically, a high chart graph. However, I've encountered a challenge with the rendering of these charts using a directive. Curr ...

Is the Expand All / Collapse All feature malfunctioning when used with a tree table?

I have been working on implementing the Expand All/Collapse All feature for a nested tree table, but unfortunately, I am not achieving the desired output. I referred to a related question on this topic which can be found here. You can also view the code on ...

navigate to a new page in vue with node.js

As I continue to expand my knowledge in JavaScript, Vue, and Node.js, I encountered a specific issue that I need help with. My goal is to redirect the Vue page after logging in using Node.js. Below you'll find the code snippets for my Vue setup and sc ...

Discovering child elements within an iframe using Angular and customizing their appearance

Is there a simple and effective way to locate child nodes within an iframe using Angular in order to access the HTML element? Currently, I have implemented the following method: I designated a reference variable within my iframe (#privacyPolicy) <ifra ...

The Vuetify App Bar is excessive in height, dominating half of the screen

Is it just me, or does the app bar take up half of the page when you have an otherwise empty app with a v-app-bar inside of the v-app container? <v-app> <v-app-bar color="deep-purple" dark > <v-toolbar-title>Page title</v-toolb ...

Determine total and showcase it as the range slider is adjusted

Seeking to calculate and present the result of three range sliders. The equation I aim to showcase is: KM driven per year * Avg KM/100L / Price of fuel I have managed to display each slider's individual values, but I am uncertain about how to show t ...

Issue with Bcrypt comparison resulting in constant false output

Attempting to implement password verification using bcryptjs, const bcrypt = require('bcryptjs'); login(post){ this.uid = post.uid; this.pin = post.pin; this.getUser(this.uid); if(this.checkUser != undefined ...

Submitting a Laravel form seamlessly without triggering a page refresh

In my Laravel 5.7 Project, I have a dilemma that needs resolving: Within my system, there is a table displaying all users with a column labeled Status, indicating whether they are Active or Inactive... Currently, in my Blade template, there is a select o ...

Place the token within the Nuxt auth-module

Working on a project using the Nuxt auth-module. The Login API response is structured like this: data:{ data:{ user:{ bio: null, createdAt: "2021-06-29T12:28:42.442Z", email: "<a href="/cdn- ...

Vercel Next JS features server and client components with distinct timezones

In my Next.js 13.2.4 project, there is a useful helper function named getLocalTime(date) that retrieves the local time of the user's machine in a specific format. //Desired output: 9:30PM export function getLocalTime(date) { const localTime = new D ...

Find the location where the function is declared

Can anyone help me locate the definition of this function: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#copyObject-property copyObject(params = {}, callback) ⇒ AWS.Request I'm struggling to find where it is defined. Any suggestio ...

Combine and interchange horizontal and vertical form designs within antd 5 for a personalized touch

I need to customize the layout of a form to display checkboxes in vertical mode. Specifically, there is a row of checkboxes that I want to appear vertically aligned rather than horizontally. In the past, I was able to achieve this in antd 4 by applying a ...

Adding and removing controls on Google Maps in real-time

Recently, I encountered an issue with my custom search bar overlapping some controls on my map. Despite adjusting the z-index of these controls, they continued to stay on top. To work around this problem, I thought about hiding the controls during the sear ...

Experience the mesmerizing motion of a D3.js Bar Chart as it ascends from the bottom to the top. Feel free to

Here is the snippet of code I am working with. Please check the link for the output graph demonstration. [Click here to view the output graph demo][1] (The current animation in the output is from top to bottom) I want to animate the bars from Bottom to ...