1 Star 0 Fork 0

ting0008x / vue-swiper5

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Vue-Swiper5

Swiper5 component for Vue, support pc and mobile, SPA

Example

Install

NPM

npm install vue-swiper5 --save

Mount

mount with global

import Vue from 'vue'
import VueSwiper5 from 'vue-swiper5'

// require styles
import 'swiper/css/swiper.css'

Vue.use(VueSwiper5, /* { default global options } */)

mount with component

// require styles
import 'swiper/css/swiper.css'

import { swiper } from 'vue-swiper5'

export default {
  components: {
    swiper
  }
}

custom swiper plugin

import Swiper from 'swiper'
Swiper.use({
  name: 'pluginName',
  params: {
    pluginSwitch: false,
  },
  on: {
    init() {
      if (!this.params.pluginSwitch) return
      console.log('init')
    },
    // swiper callback...
  }
})

SPA

<!-- The ref attr used to find the swiper instance -->
<template>
  <swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
    <!-- slides -->
    <template v-slot:items>
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div>
    </template>
    <!-- Optional controls -->
    <template v-slot:controls>
        <div class="swiper-pagination"></div>
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>
        <div class="swiper-scrollbar"></div>
    </template>
  </swiper>
</template>

<script>
  export default {
    name: 'carrousel',
    data() {
      return {
        swiperOption: {
          // some swiper options/callbacks
        }
      }
    },
    computed: {
      swiper() {
        return this.$refs.mySwiper.swiper
      }
    },
    mounted() {
      // current swiper instance
      console.log('this is current swiper instance object', this.swiper)
      this.swiper.slideTo(3, 1000, false)
    }
  }
</script>

Async data example

<template>
  <swiper :options="swiperOption">
    <template v-slot:items>
        <div class="swiper-slide" v-for="(slide, index) in swiperSlides" :key="index">I'm Slide {{ slide }}</div>
    </template>
    <!-- Optional controls -->
    <template v-slot:controls>
        <div class="swiper-pagination"></div>
    </template>
  </swiper>
</template>

<script>
  export default {
    name: 'carrousel-items',
    data() {
      return {
        swiperOption: {
          pagination: {
            el: '.swiper-pagination'
          }
        },
        swiperSlides: [1, 2, 3, 4, 5]
      }
    },
    mounted() {
      setInterval(() => {
        console.log('simulate async data')
        if (this.swiperSlides.length < 10) {
          this.swiperSlides.push(this.swiperSlides.length + 1)
        }
      }, 3000)
    }
  }
</script>

API

Swiper's API and configuration can be used.

空文件

简介

暂无描述 展开 收起
Vue 等 2 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/ting0008x/vue-swiper5.git
git@gitee.com:ting0008x/vue-swiper5.git
ting0008x
vue-swiper5
vue-swiper5
master

搜索帮助