vue+swiper使用

目录

vue+swiper使用

一、安装
npm i -S swiper@5 vue-awesome-swiper
二、main.js
import VueAwesomeSwiper from 'vue-awesome-swiper'
// swiper版本5
import 'swiper/css/swiper.css'
// 第二个参数可配置默认选项
Vue.use(VueAwesomeSwiper, {})
三、使用
<template>
  <div class="dashboard-container">
    <swiper ref="swiper" class="swiper" :options="swiperOption">
      <swiper-slide>Resize me 1</swiper-slide>
      <swiper-slide>Resize me 2</swiper-slide>
      <swiper-slide>Resize me 3</swiper-slide>
      <swiper-slide>Resize me 4</swiper-slide>
      <swiper-slide>Resize me 5</swiper-slide>
      <swiper-slide>Resize me 6</swiper-slide>
      <div slot="pagination" class="swiper-pagination" />
      <div slot="button-prev" class="swiper-button-prev" />
      <div slot="button-next" class="swiper-button-next" />
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'Dashboard',
  data() {
    return {
      swiperOption: {
        slidesPerView: 3,
        spaceBetween: 30,
        direction: 'horizontal',
        pagination: {
          el: '.swiper-pagination'
        },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        },
        on: {
          resize: () => {
            this.$refs.swiper.$swiper.changeDirection(
              window.innerWidth <= 960
                ? 'vertical'
                : 'horizontal'
            )
          }
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .dashboard {
    &-container {
      margin: 30px;
    }

    &-text {
      font-size: 30px;
      line-height: 46px;
    }
  }

  .swiper {
    height: 300px;
    width: 100%;

    .swiper-slide {
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
      font-weight: bold;
      font-size: 36.4px;
      background-color: white;
    }
  }

  @media (max-width: 960px) {
    .swiper-button-next {
      right: 20px;
      transform: rotate(90deg);
    }

    .swiper-button-prev {
      left: 20px;
      transform: rotate(90deg);
    }
  }
</style>
四、在线示例

https://github.surmon.me/vue-awesome-swiper/

上一篇:Android Studio 点击按钮跳转到另一个Activity


下一篇:QT软件开发之基础控件--2.1.6 buttonBox按钮盒