更新记录
1.0.0(2025-05-27)
新增
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 3.1.0 app-vue app-nvue |
× |
√ |
√ |
√ |
× |
√ |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
√ |
√ |
√ |
√ |
√ |
× |
√ |
√ |
√ |
Banner Swiper 轮播图组件
一个功能强大、高度可定制的 Banner 轮播图组件,支持自定义指示器和插槽内容。
平台兼容性
App-vue |
App-nvue |
H5 |
微信小程序 |
支付宝小程序 |
百度小程序 |
抖音小程序 |
QQ小程序 |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
基础用法
默认用法(显示图片)
<template>
<banner-swiper :bannerList="bannerList"></banner-swiper>
</template>
<script>
export default {
data() {
return {
bannerList: [
{
Picture: '图片地址',
LinkUrl: '点击跳转链接'
},
{
Picture: '另一张图片地址',
LinkUrl: '另一个跳转链接'
}
]
}
}
}
</script>
使用插槽自定义内容
可以通过默认插槽来自定义每个轮播项的内容。插槽会暴露 item
(当前轮播项的数据) 和 index
(当前轮播项的索引) 给您使用。
<template>
<banner-swiper :bannerList="bannerList">
<template v-slot:default="{ item, index }">
<!-- 在这里放置您的自定义内容 -->
<view class="custom-item">
<text>{{ item.Title || '自定义内容 ' + index }}</text>
<!-- 您可以根据 item 数据渲染任何内容 -->
<image v-if="item.Picture" :src="item.Picture" mode="aspectFill" class="custom-image"></image>
<!-- 也可以添加点击事件等 -->
<button @click="handleCustomClick(item)">点击</button>
</view>
</template>
</banner-swiper>
</template>
<script>
export default {
data() {
return {
bannerList: [
{ id: 1, Title: '商品A', Picture: '图片A地址', LinkUrl: '页面A' },
{ id: 2, Title: '商品B', Picture: '图片B地址', LinkUrl: '页面B' }
]
}
},
methods: {
handleCustomClick(item) {
console.log('点击了自定义内容', item);
// 处理点击逻辑,例如跳转页面
if (item.LinkUrl) {
uni.navigateTo({
url: item.LinkUrl
});
}
}
}
}
</script>
<style>
.custom-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-color: #eee;
font-size: 30rpx;
}
.custom-image {
width: 80%;
height: 80%;
margin-top: 20rpx;
}
</style>
API
Props
属性名 |
类型 |
默认值 |
说明 |
bannerList |
Array |
[] |
轮播图数据列表,每个项目通常需包含 Picture(图片地址)和 LinkUrl(点击跳转链接)属性。如果使用插槽,可以传递任何您需要的数据。 |
height |
String |
'78vh' |
轮播图容器高度,支持 rpx、px、vh 等单位 |
indicatorWidth |
String |
'400rpx' |
指示器宽度 |
indicatorHeight |
String |
'8rpx' |
指示器高度 |
indicatorBottom |
String |
'10%' |
指示器距离底部距离 |
indicatorBgColor |
String |
'rgba(0, 0, 0, 0.5)' |
指示器背景色 |
indicatorActiveColor |
String |
'#fff' |
指示器激活色 |
circular |
Boolean |
true |
swiper参数:是否采用衔接滑动 |
indicatorDots |
Boolean |
false |
swiper参数:是否显示面板指示点 |
autoplay |
Boolean |
true |
swiper参数:是否自动切换 |
interval |
Number |
3000 |
swiper参数:自动切换时间间隔(ms) |
duration |
Number |
1000 |
swiper参数:滑动动画时长(ms) |
current |
Number |
0 |
swiper参数:当前所在滑块的 index |
displayMultipleItems |
Number |
1 |
swiper参数:同时显示的滑块数量 |
nextMargin |
String |
'0px' |
swiper参数:后边距,可用于露出后一项的一小部分 |
previousMargin |
String |
'0px' |
swiper参数:前边距,可用于露出前一项的一小部分 |
vertical |
Boolean |
false |
swiper参数:滑动方向是否为纵向 |
Events
事件名 |
说明 |
回调参数 |
change |
轮播图切换时触发 |
当前索引值 |
transition |
滑动动画过渡时触发 |
事件对象 |
animationfinish |
滑动动画结束时触发 |
事件对象 |
自定义样式
组件提供了以下类名供自定义样式:
.banner-container
: 轮播图容器
.banner-swiper
: 轮播图主体
.banner-image
: 轮播图片
.custom-indicator-container
: 指示器容器
.indicator-background
: 指示器背景
.indicator-foreground
: 指示器前景
.custom-item
: 插槽内的自定义内容容器示例类名
.custom-image
: 插槽内图片示例类名
示例
自定义高度和指示器样式
<template>
<banner-swiper
:bannerList="bannerList"
height="500rpx"
indicatorWidth="300rpx"
indicatorHeight="6rpx"
indicatorBottom="20rpx"
indicatorBgColor="rgba(255, 255, 255, 0.3)"
indicatorActiveColor="#ff0000"
></banner-swiper>
</template>
自定义轮播图行为
<template>
<banner-swiper
:bannerList="bannerList"
:autoplay="true"
:interval="5000"
:duration="800"
:circular="true"
:display-multiple-items="1"
:next-margin="'20rpx'"
:previous-margin="'20rpx'"
:vertical="false"
></banner-swiper>
</template>
版本说明
-
标准版:5.99元
-
源码版:19.99元
- 包含标准版所有功能
- 提供完整源代码
- 支持自定义修改
- 提供技术支持
联系方式