简体   繁体   English

如何仅在移动网格上使用 vue-awesome-swiper 组件

[英]How to use vue-awesome-swiper component only on mobile grid

I have two bootstrap cols with content.我有两个带有内容的引导程序。 On a large scale, cols are getting half of the row and on a mobile scale, cols are getting all row width and sitting one above another, like a typical grid.在大尺度上,cols 占据了行的一半,而在移动尺度上,cols 占据了所有的行宽,并且一个排在另一个之上,就像一个典型的网格。 I want to use the vue-awesome-swiper on a mobile scale so that I can swipe columns instead of scrolling down to a bottom col.我想在移动规模上使用 vue-awesome-swiper,这样我就可以滑动列而不是向下滚动到底部。 At the same time, I don't need swiper on a large scale, where columns fit one-row width.同时,我不需要大规模的 swiper,列适合一行宽度。 How can I rich it?我怎样才能发财呢? How to use the vue-awesome-swiper component only on a mobile scale and don't use it on large one.如何仅在移动规模上使用 vue-awesome-swiper 组件,而不是在大型规模上使用它。 Some code to illustrate the case:一些代码来说明这种情况:

<div class="row h-100">
   <div class="col gauche">
      <!-- Some content here -->
   </div>
   <div class="col gauche">
      <!-- Some content here -->
    </div>
</div>

With swiper:带刷卡器:

<div class="row h-100">
   <swiper class="swiper">
     <swiper-slide>
       <div class="col gauche">
          <!-- Some content here -->
       </div>
     </swiper-slide>
     <swiper-slide>
       <div class="col gauche">
          <!-- Some content here -->
       </div>
     </swiper-slide>
   </swiper>
</div>

The simple solution to this problem (but not the prettiest), would be to use Bootstrap's display utilities , to define when your slider should show and when your columns should show.这个问题的简单解决方案(但不是最漂亮的)是使用 Bootstrap 的显示实用程序来定义 slider 何时显示以及列何时显示。

The bad part about this solution is having to define your content twice.这个解决方案的坏处是必须定义你的内容两次。 Once for the normal columns, and once for the slides.一次用于普通列,一次用于幻灯片。

In the below example i "swap" at the md breakpoint, but you can change this to what fits your needs.在下面的示例中,我在md断点“交换”,但您可以将其更改为适合您的需要。

<div class="row d-none d-md-flex">
  <div class="col-md-6" v-for="{ text } in items">
    <column-content :text="text"></column-content>
  </div>
</div>
<div class="row d-md-none">
  <div class="col-12">
    <swiper>
      <swiper-slide v-for="{ text } in items" class="px-2">
        <column-content :text="text"></column-content>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</div>

 Vue.use(VueAwesomeSwiper) Vue.component('column-content', { template: '#column-content', props: ['text'], data() { return { text: '123'} } }) new Vue({ el: '#app', data() { return { items: [ { text: 'Some Text 1' }, { text: 'Some Text 2' }, ] } } })
 <link href="https://unpkg.com/bootstrap@4.5.0/dist/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://cdn.jsdelivr.net/npm/swiper@5.3.6/css/swiper.min.css" rel="stylesheet"/> <script src="https://unpkg.com/vue@2.6.11/dist/vue.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/swiper@5.3.6/js/swiper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue-awesome-swiper"></script> <div id="app"> <div class="container"> <div class="row d-none d-md-flex"> <div class="col-md-6" v-for="{ text } in items"> <column-content:text="text"></column-content> </div> </div> <div class="row d-md-none"> <div class="col-12"> <swiper> <swiper-slide v-for="{ text } in items" class="px-2"> <column-content:text="text"></column-content> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> </swiper> </div> </div> </div> </div> <template id="column-content"> <div class="card"> <div class="card-body"> {{ text }} </div> </div> </template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM