触发“ vue-owl-carousel”包Vue.js中的下一个和上一个元素

问题描述 投票:0回答:1

我在使用javascript触发Vue的vue-owl-carousel包中的下一个或上一个项目时遇到问题。

有人可以帮忙吗?

轮播代码:

<carousel id="newGamesCarousel" :items="1" :dots="false" :nav="false" :margin="10" :key="refresh">
  <div class="newGames-item" v-for="item in newProducts">
    <div class="details">
      <div class="labels flex-wrap">
        <span class="mb-1" v-for="platform in item.platforms">{{platform.name}}</span>
        <span class="mb-1" v-for="region in item.regions">ریجن {{region.name}}</span>
      </div>
      <h2 class="gameTitle">{{item.name}}</h2>
      <div class="priceBox">
        <router-link class="add-to-cart" :to="{path: '/game/'+item.id+'/'+stringToSlug(item.title)+''}">+</router-link>
        <div class="price">
          <div class="former" v-if="item.sale_percent !== false">
            <span class="percent">%{{item.sale_percent}}</span>
            <span class="total">{{item.price}}</span>
          </div>
          <div class="later">
            {{item.regular_price}}
            <span class="unit">تومان</span>
          </div>
        </div>
      </div>
    </div>

    <figure class="image">
      <img v-bind:src="item.thumbnail_url" v-bind:alt="item.name">
    </figure>
  </div>
</carousel>

以及下一个和上一个按钮:

<div class="arrows">
  <svg class="nextCarousel" id="newGamesNext" viewBox="0 0 24 24">
    <use xlink:href="/src/assets/imgs/sprite.svg#arrow"></use>
  </svg>
  <svg class="prevCarousel" id="newGamesPrev" viewBox="0 0 24 24">
    <use xlink:href="/src/assets/imgs/sprite.svg#arrow"></use>
  </svg>
</div>
javascript vue.js vuejs2 owl-carousel owl-carousel-2
1个回答
0
投票

根据此处描述的文档:https://www.npmjs.com/package/vue-owl-carousel

使用插槽自定义上一个和下一个按钮,这些按钮将被隐藏在非循环模式下开始和结束时

<carousel>

  <template slot="prev"><span class="prev">prev</span></template>

  <template slot="next"><span class="next">next</span></template>

</carousel>

添加所有幻灯片后,在carousel标签内

您可以添加<template slot="{{prev/next}}">{{add your icon image here }}</template>,它应该自己处理上一个和下一个事件

<template slot="prev">
   <svg class="nextCarousel" id="newGamesNext" viewBox="0 0 24 24"><use xlink:href="/src/assets/imgs/sprite.svg#arrow"></use></svg>
</template>

这就是我认为应该解决的问题。如果我错过了一些东西,可以随意添加文档/教程的URL,然后按照这些URL在此处获取代码。请让我知道解决方案是否有效

© www.soinside.com 2019 - 2024. All rights reserved.