搜尋

首頁  >  問答  >  主體

使用 Vue.js 在 Swiper 中建立用於幻燈片導航的自訂按鈕

我需要刪除預設導覽(nextEl、prevEl)並使帶有「下一張投影片按鈕」文字的按鈕捲動到下一張投影片

<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>

我怎麼才能做到這一點?我將非常感謝您的幫助

P粉035600555P粉035600555389 天前707

全部回覆(1)我來回復

  • P粉294954447

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

    這應該可以做到,您需要做的就是導入useSwiper 並將其分配給const 變量,然後在div 元素中將其用作swiper.slideNext()

    如果您不想使用 swiper 自己的元素,請刪除 navigation 模組。

    這是更清晰的文件來源

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

    回覆
    0
  • 取消回覆