swiper
滑块视图容器。
| 属性 | 类型 | 默认值 | 说明 | 版本 | 
|---|---|---|---|---|
| indicator-dots | boolean | false | 是否显示面板指示点 | |
| indicator-color | string | rgba(0, 0, 0, 0.3) | 指示点颜色 | |
| indicator-active-color | string | #000000 | 当前选中的指示点颜色 | |
| autoplay | boolean | false | 是否自动切换 | |
| current | number | 0 | 当前所在滑块的index | |
| current-item-id | string | 当前所在滑块的 item-id ,不能与 current 被同时指定 | ||
| interval | number | 5000 | 自动切换时间间隔 | |
| duration | number | 500 | 滑动动画时长 | |
| circular | boolean | false | 是否采用衔接滑动 | |
| vertical | boolean | false | 滑动方向是否为纵向 | |
| change | eventhandle | current 改变时会触发 change 事件,event.detail = { current: current, source: source } | ||
| animationfinish | eventhandle | 动画结束时会触发 animationfinish 事件,event.detail 同上 | 
change事件返回detail中包含一个source字段,表示导致变更的原因,可能值如下:
- autoplay自动播放导致swiper变化;
- touch用户划动引起swiper变化;
- 其他原因将用空字符串表示。
注意:swiper中只可放置swiper-item组件,否则会导致未定义的行为。
swiper-item
仅可放置在swiper组件中,宽高自动设置为100%,bilibili小程序中,swiper-item等同于div。
| 属性 | 类型 | 默认值 | 说明 | 版本 | 
|---|---|---|---|---|
| item-id | string | 该 swiper-item 的标识符 | 
实例代码
<template>
  <swiper
      :current="currentIndex"
      :indicator-dots="showDots"
      :autoplay="autoplay"
      :duration="duration"
      previous-margin="30px"
      next-margin="30px"
      :interval="interval"
      @change="handleChange"
      @animationfinish="handleChange"
  >
    <swiper-item :item-id="index"
                 v-for="index in length"
                 :key="index"
                 :style="{'background': `rgb(${50 * index},${50 * index},${50 * index})`}"></swiper-item>
  </swiper>
</template>
<script>
export default {
  data() {
    return {
      length: 5,
      duration: 500,
      interval: 5000,
      currentIndex: 0,
      showDots: true,
      autoplay: false
    };
  },
  methods: {
    handleChange(e) {
      console.log(e);
    }
  }
}
</script>
<style lang="less" scoped>
</style>