【问题标题】:Trigger next and previous element in 'vue-owl-carousel' package Vue.js触发'vue-owl-carousel'包Vue.js中的下一个和上一个元素
【发布时间】:2020-03-15 12:31:35
【问题描述】:

我在使用 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】:

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

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

<carousel>

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

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

</carousel>

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

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

<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,以便在此处获取您的代码。请让我知道解决方案是否有效

【讨论】:

    【解决方案2】:
    <v-flex>
      <span @click="$refs.prev.click()">
          PREVIOUS
      </span>
      <span @click="$refs.next.click()">
          NEXT 
      </span>
    </v-flex>
    
    
    <v-flex>
    
      <carousel>
    
       <template slot="prev"><span hidden ref="prev" class="prev">prev</span></template>
    
       <template slot="next"><span hidden  ref="next" class="next">next</span></template>
    
      </carousel>
    
    </v-flex>
    

    【讨论】:

    • 不要只发布代码解决方案。请在您的答案中添加一些细节。
    猜你喜欢
    • 2015-08-29
    • 2017-11-03
    • 1970-01-01
    • 2017-05-25
    • 2014-10-07
    • 1970-01-01
    • 2021-04-26
    • 2018-11-25
    • 2017-07-15
    相关资源
    最近更新 更多