更新记录
1.0.0(2024-12-11) 下载此版本
无
平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | - | - | - | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | - | √ | √ | √ | √ |
其他
多语言 | 暗黑模式 | 宽屏模式 |
---|---|---|
× | × | √ |
轮播图组件使用文档
1. 组件介绍
这是一个功能丰富的 uniapp 轮播图组件,支持水平/垂直轮播、自定义指示器、标题显示、遮罩效果、卡片效果等多种功能。
2. 安装使用
2.1 安装
将 my-swiper
组件复制到项目的 components
目录下。
2.2 引入组件
import MySwiper from '@/components/my-swiper/my-swiper.vue'
export default {
components: {
MySwiper
}
}
3. 基础用法
3.1 水平轮播
<template>
<my-swiper
:list="swiperList"
:options="swiperOptions"
:height="250"
@change="onChange"
/>
</template>
<script>
export default {
data() {
return {
swiperList: [
{
id: 1,
image: 'path/to/image1.jpg',
title: '标题1',
subtitle: '副标题1',
url: '/pages/detail/detail?id=1'
}
],
swiperOptions: {
autoplay: true,
interval: 3000,
customIndicator: true,
showTitle: true
}
}
}
}
</script>
3.2 垂直轮播
<my-swiper
:list="swiperList"
:options="{
verticalOptions: {
enabled: true,
height: '300rpx',
spacing: '0'
},
customIndicator: true,
indicatorPosition: 'right'
}"
:height="300"
/>
4. API
4.1 Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
list | Array | [] | 轮播图数据列表 |
options | Object | {} | 轮播图配置项 |
height | String/Number | '400rpx' | 轮播图高度 |
width | String/Number | '100%' | 轮播图宽度 |
radius | String/Number | '0' | 图片圆角 |
4.2 数据结构
interface SwiperItem {
id: number; // 唯一标识
image: string; // 图片地址
title?: string; // 标题(可选)
subtitle?: string; // 副标题(可选)
url?: string; // 点击跳转链接(可选)
}
4.3 配置项(options)
基础配置
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
autoplay | Boolean | true | 是否自动播放 |
interval | Number | 3000 | 自动切换时间间隔(ms) |
duration | Number | 500 | 滑动动画时长(ms) |
circular | Boolean | true | 是否循环播放 |
指示器配置
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
customIndicator | Boolean | false | 是否使用自定义指示器 |
indicatorPosition | String | 'bottom' | 指示器位置:'bottom'/'bottomLeft'/'bottomRight'/'right' |
indicatorStyle | Object | {} | 指示器样式 |
标题配置
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
showTitle | Boolean | false | 是否显示标题 |
titlePosition | String | 'bottom' | 标题位置:'bottom'/'overlay' |
titleStyle | Object | {} | 标题样式 |
效果配置
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
showOverlay | Boolean | false | 是否显示遮罩 |
overlayGradient | Boolean | false | 是否使用渐变遮罩 |
cardEffect | Boolean | false | 是否启用卡片效果 |
shadowEffect | Boolean | false | 是否启用阴影效果 |
animationMode | String | 'default' | 动画模式:'default'/'fade'/'flip'/'cube'/'zoom' |
垂直轮播配置
verticalOptions: {
enabled: Boolean, // 是否启用垂直轮播
height: String, // 垂直轮播高度
spacing: String // 垂直间距
}
4.4 事件
事件名 | 说明 | 回调参数 |
---|---|---|
change | 轮播切换事件 | index: 当前索引 |
click | 点击事件 | item: 当前项数据 |
animationfinish | 动画结束事件 | e: 动画完成事件对象 |
imageload | 图片加载完成 | index: 图片索引 |
error | 图片加载失败 | {index, image} |
5. 示例
5.1 卡片式轮播
swiperOptions: {
cardEffect: true,
shadowEffect: true,
imageRadius: '16rpx',
customIndicator: true,
indicatorPosition: 'bottomRight'
}
5.2 带渐变标题的轮播
swiperOptions: {
showTitle: true,
titlePosition: 'overlay',
showOverlay: true,
overlayGradient: true,
titleStyle: {
background: 'linear-gradient(to top, rgba(0,0,0,0.7), transparent)',
padding: '40rpx 20rpx 20rpx'
}
}
5.3 自定义垂直轮播
swiperOptions: {
verticalOptions: {
enabled: true,
height: '300rpx'
},
customIndicator: true,
indicatorPosition: 'right',
indicatorStyle: {
right: '40rpx',
padding: '5rpx',
background: 'rgba(0, 0, 0, 0.3)',
borderRadius: '10rpx'
}
}
6. 注意事项
-
图片资源
- 建议使用相同尺寸的图片
- 支持本地图片和网络图片
- 建议图片进行压缩优化
-
性能优化
- 合理设置自动播放间隔
- 避免同时使用过多动画效果
- 图片预加载优化
-
样式调整
- 可通过 titleStyle 和 indicatorStyle 自定义样式
- 注意 z-index 层级关系
- 垂直轮播时注意内容布局
7. 常见问题
-
图片不显示
- 检查图片路径是否正确
- 确认图片资源是否可访问
- 查看是否有跨域限制
-
指示器位置不正确
- 检查 indicatorPosition 配置
- 确认 indicatorStyle 样式设置
- 垂直轮播时注意指示器方向
-
动画效果不生效
- 确认 animationMode 配置正确
- 检查是否与其他动画效果冲突
- 查看是否支持相关CSS属性