search

Home  >  Q&A  >  body text

Create custom buttons for slide navigation in Swiper using Vue.js

I need to remove the default navigation (nextEl, prevEl) and make the button with the text "Next Slide Button" scroll to the next slide

<swiper class="news-slider" :sliderd-per-view="1" :modules="[Navigation, Pagination, A11y, Lazy]" navigation="navigation" :navigation="{ nextEl: '.nextArrow'}" :pagination="{ clickable: true, dynamicBullets: true, dynamicMainBullets: 5 }" preload-images="false" lazy="lazy"> 
  <swiperSlide class="swiper-slide" v-for="n in 10" :key="n">
    <div class="news-container"> 
      <div class="news"><img class="news__image swiper-lazy" src="@/assets/img/lookism-transformed-transformed.png" alt=""/>
        <div class="swiper-lazy-preloader"></div>
        <div class="news__info">
          <div class="news__title">title</div>
          <div class="news__description">description</div>
          <div class="news__buttons">
            <button class="normal-button news-button">more</button>
            <button class="next-button"><span class="next-button__text">NEXT SLIDE BUTTON</span><img class="next-button__icon" src="@/assets/img/arrow-right.svg" alt=""/></button>
          </div>
        </div>
      </div>
    </div>
  </swiperSlide>
</swiper>

<script>
  export default {
    components: {
      Swiper,
      SwiperSlide,
    },
    setup() {
      const onSwiper = (swiper) => {
        console.log(swiper);
        
      };
      const onSlideChange = () => {
        console.log('slide change');
      };
      return {
        onSwiper,
        onSlideChange,
        modules: [Navigation, Pagination, Scrollbar, A11y],
      };
    },
  };
</script>

How can I do this? I will be very grateful for your help

P粉035600555P粉035600555389 days ago709

reply all(1)I'll reply

  • P粉294954447

    P粉2949544472023-11-03 11:27:25

    This should do the trick, all you need to do is import useSwiper and assign it to a const variable and then use it inside the div element as swiper.slideNext()

    If you don't want to use swiper on your own elements, remove the navigation module.

    This is a clearer documentation source

    https://swiperjs.com/vue#use-swiper

    reply
    0
  • Cancelreply