更新记录
2.0.0(2026-11-11) 下载此版本
fix
1.0.2(2026-11-11) 下载此版本
增加支持自定义指示器、标题遮罩、图片容错、触摸暂停、懒加载与受控切换
1.0.1(2024-11-25) 下载此版本
新增:click事件 新增:错误图设置 修复:图片error的触发导致其他的都设置为错误图
查看更多平台兼容性
uni-app x(5.34)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| √ | √ | 5.0 | √ | - | - |
其他
| 多语言 | 暗黑模式 | 宽屏模式 | 蒸汽模式 |
|---|---|---|---|
| × | × | √ | × |
gm-swiper
基于 uni-app x(uvue)的轮播组件,支持自定义指示器、标题遮罩、图片容错、触摸暂停、懒加载与受控切换。
使用说明
<template>
<gm-swiper :items="banner" :height="160" :radius="12" indicator="dot" @click="onClick" @change="onChange" />
</template>
<script setup lang="uts">
import { ref } from 'vue'
const banner = ref<Array<any>>([
{ id: 1, src: 'https://example.com/1.png', title: '第一张' },
{ id: 2, src: 'https://example.com/2.png', title: '第二张' }
])
function onClick(index : number, item : any) {
console.log('click', index, item)
}
function onChange(index : number) {
console.log('change', index)
}
</script>
基础用法(v-model 受控 + 方法调用)
<gm-swiper ref="swiperRef" v-model="current" :items="banner" indicator="number" show-title />
const swiperRef = ref<any>(null)
swiperRef.value?.prev()
swiperRef.value?.next()
swiperRef.value?.goTo(2)
参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| items | Array | [] | 轮播数据,结构 [{ id, src, title }] |
| modelValue | Number | 0 | 当前索引,支持 v-model |
| height | Number | 150 | 轮播区域高度(px) |
| radius | Number | 10 | 圆角(px) |
| imageMode | String | aspectFill | 图片裁剪模式:aspectFill / aspectFit / scaleToFill / widthFix |
| autoplay | Boolean | true | 是否自动轮播 |
| interval | Number | 3000 | 自动切换间隔(ms) |
| duration | Number | 500 | 切换动画时长(ms) |
| circular | Boolean | true | 是否循环轮播 |
| vertical | Boolean | false | 是否纵向轮播 |
| indicator | String | dot | 指示器类型:dot / line / number / none |
| indicatorColor | String | rgba(255,255,255,0.5) | 指示器颜色 |
| indicatorActiveColor | String | #FFFFFF | 当前指示器颜色 |
| showTitle | Boolean | false | 是否显示标题遮罩 |
| srcKey | String | src | 图片字段名映射 |
| titleKey | String | title | 标题字段名映射 |
| idKey | String | id | 唯一标识字段名映射(用于列表 key) |
| errorSrc | String | '' | 图片加载失败时的兜底图,为空则显示占位文案 |
| emptyText | String | 暂无内容 | 空数据 / 加载失败的占位文案 |
| bgColor | String | #F3F4F6 | 占位背景色 |
| pauseOnTouch | Boolean | true | 触摸时暂停自动播放,松手恢复 |
| lazyLoad | Boolean | false | 懒加载,仅渲染当前项及前后项 |
事件
| 名称 | 回调参数 | 说明 |
|---|---|---|
| click | (index: number, item: any) | 点击轮播项时触发 |
| change | (index: number) | 切换到新面板时触发 |
| update:modelValue | (index: number) | 当前索引变化,配合 v-model 使用 |
方法
通过组件 ref 调用:
| 名称 | 参数 | 说明 |
|---|---|---|
| prev | - | 切换到上一张 |
| next | - | 切换到下一张 |
| goTo | (index: number) | 切换到指定索引 |
从 1.x 升级
| 1.x | 2.x |
|---|---|
list |
items |
数据字段 pic |
数据字段 src(可用 srcKey 自定义) |
dots |
indicator="dot" / indicator="none" |
errimg |
errorSrc |
click(id) |
click(index, item) |
说明:1.x 中图片加载失败会直接改写传入的 list 数据,2.x 改为组件内部记录错误索引,不再污染业务数据。

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 34
赞赏 0
下载 12758595
赞赏 1959
赞赏
京公网安备:11010802035340号