# Swiper 轮播图 
统一封装
# 基础用法
<template>
<qinui-swiper :data="theList"/>
</template>
<script>
export default {
data() {
return {
theList: [
'https://cdn.uviewui.com/uview/swiper/swiper1.png',
'https://cdn.uviewui.com/uview/swiper/swiper2.png',
'https://cdn.uviewui.com/uview/swiper/swiper3.png',
],
};
},
};
</script>
# 点指示器
indicatorMode="dot"
<template>
<qinui-swiper :data="theList" indicatorMode="dot"/>
</template>
<script>
export default {
data() {
return {
theList: [
'https://cdn.uviewui.com/uview/swiper/swiper1.png',
'https://cdn.uviewui.com/uview/swiper/swiper2.png',
'https://cdn.uviewui.com/uview/swiper/swiper3.png',
],
};
},
};
</script>
# 嵌入视频
设置 :auto-line-width="false"
<template>
<qinui-swiper
:data="theList"
:autoplay="false"
height="500rpx"
/>
</template>
<script>
export default {
data() {
return {
theNow: 'ey',
theList: [
{
url: 'https://cdn.uviewui.com/uview/resources/video.mp4',
title: '昨夜星辰昨夜风,画楼西畔桂堂东',
poster: 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
},
{
url: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
title: '身无彩凤双飞翼,心有灵犀一点通',
},
{
url: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
title: '谁念西风独自凉,萧萧黄叶闭疏窗,沉思往事立残阳',
},
],
};
},
};
</script>
# 自定义指示器
<template>
<qinui-swiper :data="theList1" @change="onChange1" :autoplay="false">
<template #indicator>
<view class="indicator">
<view
class="indicator__dot"
v-for="(_, theIndex) in theList1"
:key="theIndex"
:class="[theIndex === theNow && 'indicator__dot--active']"
>
</view>
</view>
</template>
</qinui-swiper>
</template>
<script>
export default {
data() {
return {
theNow: 0,
theList: [
'https://cdn.uviewui.com/uview/swiper/swiper1.png',
'https://cdn.uviewui.com/uview/swiper/swiper2.png',
'https://cdn.uviewui.com/uview/swiper/swiper3.png',
],
};
},
methods: {
onChange1: (theEv) => {
this.theNow1 = theEv.current;
};
}
};
</script>
<style lang="scss">
.indicator {
display: flex;
flex-direction: row;
justify-content: center;
&__dot {
height: 6px;
width: 20rpx;
border-radius: 100px;
background-color: rgba(255, 255, 255, 0.35);
margin: 0 5px;
transition: background-color 0.3s;
&--active {
background-color: #0f0;
width: 6px;
}
}
}
.indicator-num {
padding: 2px 0;
background-color: rgba(0, 0, 0, 0.35);
border-radius: 100px;
width: 35px;
display: flex;
flex-direction: row;
justify-content: center;
&__text {
color: #ffffff;
font-size: 12px;
}
}
</style>
# 一张
<template>
<qinui-swiper :data="theList"/>
</template>
<script>
export default {
data() {
return {
theList: [
'https://cdn.uviewui.com/uview/swiper/swiper1.png',
],
};
},
};
</script>
# API
# Swiper Props
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| data | 轮播图数据,见上方"基本使用"说明 | Array | - | - |
| indicator | 是否显示面板指示器 | Boolean | true | true | false |
| indicatorActiveColor | 指示器激活的颜色 | String | #FFFFFF | - |
| indicatorInactiveColor | 指示器非激活颜色 | String | rgba(255, 255, 255, 0.35) | - |
| indicatorStyle | 指示器样式,可通过bottom,left,right进行定位 | String | Object | - | - |
| indicatorMode | 指示器模式 | String | line | line | dot |
| autoplay | 是否自动切换 | Boolean | true | true | false |
| current | 当前所在滑块的 index | Number | String | 0 | - |
| currentItemId | 当前所在滑块的 item-id ,不能与 current 被同时指定,支付宝小程序不支持 | String | - | - |
| interval | 滑块自动切换时间间隔(ms) | String | Number | 3000 | - |
| duration | 滑块切换过程所需时间(ms) | String | Number | 300 | - |
| circular | 播放到末尾后是否重新回到开头 | Boolean | true | true | false |
| vertical1.0.4 | 滑动方向是否为纵向 | Boolean | false | true | false |
| previousMargin | 前边距,可用于露出前一项的一小部分,抖音小程序不支持 | String | Number | 0 | - |
| nextMargin | 后边距,可用于露出后一项的一小部分,抖音小程序不支持 | String | Number | 0 | - |
| acceleration | 当开启时,会根据滑动速度,连续滑动多屏,仅支付宝小程序支持 | Boolean | false | true | false |
| displayMultipleItems | 同时显示的滑块数量,nvue、支付宝小程序不支持 | Number | 1 | - |
| easingFunction | 指定swiper切换缓动动画类型, 仅支持微信小程序、快手小程序、京东小程序 | String | default | linear、easeInCubic、easeOutCubic、easeInOutCubic,参考swiper (opens new window) |
| keyName | list数组中指定对象的目标属性名 | String | url | - |
| imgMode | 图片的裁剪模式,不建议设置widthFix,如果图片比例不一样,理论上是会在切换的时候不断变化高度,实际上内部高度定死,所以是矛盾的,在部分平台显示会有异常 | String | aspectFill | 详见图片裁剪 |
| height | 组件高度 | String | Number | 130 | - |
| bgColor | 背景颜色 | String | #f3f4f6 | - |
| radius | 组件圆角,数值或带单位的字符串 | String | Number | 4 | - |
| loading | 是否加载中 | Boolean | false | true | false |
| showTitle | 是否显示标题,要求数组对象中有title属性 | Boolean | false | - |
| titleStyle | 显示的标题样式 | Object | - | - |
# Swiper Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| @click | 点击轮播图时触发 | index:点击了第几张图片,从0开始 |
| @change | 轮播图切换时触发(自动或者手动切换) | index:切换到了第几张图片,从0开始 |
# SwiperIndicator Props
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| length | 轮播的长度 | String | Number | 0 | - |
| current | 当前处于活动状态的轮播的索引 | String | Number | 0 | - |
| indicatorActiveColor | 指示器非激活颜色 | String | - | - |
| indicatorInactiveColor | 指示器的激活颜色 | String | - | - |
| indicatorStyle | 指示器的形式 | String | line | line | dot |