默认
<cu-swiper :list="strList" />
轮播用于在固定高度内轮换展示多张图片,可自动播放并叠标题与指示器。
整目录放进工程即用:easycom 按标签逐个解析,页面写哪个组件就只编译哪个,不写 import,也没有全局注册这一步;单个组件也可以显式引入(第 4 步,可选);主题层在 App.uvue 引入一次即可。
# 1 整目录放进工程(easycom 自动解析) your-project/ └── uni_modules/ └── colorui-x/ # 2 App.uvue 全局引入主题层(一次) @import 'uni_modules/colorui-x/theme/base.css'; @import 'uni_modules/colorui-x/theme/layout.css'; @import 'uni_modules/colorui-x/theme/color.scss'; // 颜色工具类(.bg-* / .text-*) # 3 页面里直接用,不写 import(只编译用到的组件) <cu-swiper /> # 4 单个组件也可以显式引入(可选,不用 easycom 时) import CuSwiper from '@/uni_modules/colorui-x/components/cu-swiper/cu-swiper.uvue'
组件样式自包含(只依赖包内 token.scss),主题层是给页面工具类用的,不参与组件注册。两种安装方式见 快速上手。
| Android | iOS | HarmonyOS | Web(H5) | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|
| √ | — | — | √ | — | — |
Android 列取自本仓真机逐屏判定(√ 已验 / — 待复核 / × 已登记缺陷,本件当前为「真机已验」)。
Web 列只表示已编出可运行的预览产物,非真机渲染。
其余三端没有任何实测证据,不作支持承诺。
<cu-swiper :list="strList" />
<cu-swiper :list="strList" :indicator="true" indicatorMode="line" /> <cu-swiper :list="strList" :indicator="true" indicatorMode="dot" :autoplay="false" />
<cu-swiper :list="strList" :indicator="true" indicatorActiveColor="red" indicatorInactiveColor="gray" indicatorMode="dot" />
<cu-swiper :list="strList" :circular="true" :interval="1000" :duration="100" :indicator="true" />
<cu-swiper :list="strList" :current="0" :indicator="true" :autoplay="false" /> <cu-swiper :list="strList" :current="2" :indicator="true" :autoplay="false" /> <cu-swiper :list="strList" :current="9" :indicator="true" :autoplay="false" />
<cu-swiper :list="emptyList" :indicator="true" />
<cu-swiper :list="strList" :height="200" :radius="0" :indicator="true" indicatorActiveColor="red" indicatorInactiveColor="gray" /> <cu-swiper :list="strList" :height="60" :radius="40" bgColor="olive" :indicator="true" />
<cu-swiper :list="strList" :loading="true" :height="120" />
<cu-swiper :list="objList" :showTitle="true" :height="180" :autoplay="false" :indicator="true" />
<cu-swiper :list="strList" :indicator="true" indicatorStyle="bottom:20rpx;left:20rpx" @change="onChange" @click="onItemClick" />
<cu-swiper :list="strList" :indicator="true" :autoplay="false" :height="180" /> <cu-swiper :list="strList" :indicator="true" :autoplay="false" :height="180" :full="true" />
<cu-swiper :list="srcKeyList" keyName="src" :indicator="true" :autoplay="false" :height="180" /> <cu-swiper :list="strList" imgMode="scaleToFill" :indicator="true" :autoplay="false" :height="180" /> <cu-swiper :list="strList" imgMode="aspectFill" :indicator="true" :autoplay="false" :height="180" />
这一节的交互由演示页脚本驱动,效果见右侧实时预览。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 数据与播放 | |||
| list | 轮播内容数组;元素可直接是图片地址,也可传带图片地址与标题的对象 | Array | (): Array<any> => [] |
| autoplay | 是否自动轮播 | Boolean | true |
| interval | 自动轮播间隔,单位毫秒 | Number | 3000 |
| duration | 单次切换动画时长,单位毫秒 | Number | 300 |
| circular | 是否首尾相接循环播放 | Boolean | false |
| current | 当前显示项下标,从 0 开始;外部改值会同步指示器 | Number | 0 |
| currentItemId | 当前显示项的 item id;与 current 二选一使用 | String | '' |
| keyName | 对象项的取图键名;只对对象项生效,串项直接当图片地址 | String | 'url' |
| 指示器 | |||
| indicator | 是否显示内置指示器;开启 showTitle 时让位给标题条 | Boolean | false |
| indicatorActiveColor | 指示器当前项的颜色 | String | '#FFFFFF' |
| indicatorInactiveColor | 指示器其余项的颜色 | String | 'rgba(255, 255, 255, 0.35)' |
| indicatorMode | line / dot,指示器取短线或圆点 | String | 'line' |
| indicatorStyle | 指示器容器的内联样式串,可写 bottom / left / right 改位置 | String | '' |
| 外观与尺寸 | |||
| imgMode | 图片裁剪模式,逐屏透传给图片节点 | String | 'aspectFill' |
| full | 铺满档(本仓扩展):图片撑满整屏,裁剪模式由组件接管为拉伸填充,源图比例不同会变形 | Boolean | false |
| height | 轮播高度,px 契约值;运行时 ×2 换算成 rpx | Number | 130 |
| bgColor | 轮播底色,图片未铺满时露出的颜色 | String | '#f3f4f6' |
| radius | 圆角,px 契约值;运行时 ×2 换算成 rpx | Number | 4 |
| loading | 加载中:只渲染同尺寸占位块,不渲染轮播内容 | Boolean | false |
| showTitle | 是否在每屏底部叠一条标题,只对带 title 的对象项生效 | Boolean | false |
| 交互与样式 | |||
| customStyle | 根节点内联样式 | Object | (): UTSJSONObject => ({}) |
| customClass | 追加到根节点的类名 | String | '' |
| 声明保留但不被消费 | |||
| previousMargin | 前一项露出的边距;本仓未接到内置轮播,传了不生效 | Number | 0 |
| nextMargin | 后一项露出的边距;本仓未接到内置轮播,传了不生效 | Number | 0 |
| acceleration | 滑动惯性开关;本仓未接到内置轮播,传了不生效 | Boolean | false |
| displayMultipleItems | 同屏渲染几项;本仓未接到内置轮播,传了不生效 | Number | 1 |
| easingFunction | 切换缓动函数;只在部分小程序端有效,本仓未接通 | String | 'default' |
| url | 不产生跳转,请在 @click 里自行处理 | String | '' |
| linkType | 不产生跳转,同上 | String | 'navigateTo' |
| 事件 | 说明 | 类型 | 默认值 | 平台差异说明 |
|---|---|---|---|---|
| @change | 轮播切换后触发,回传 { current, source } | Handler | - | 各端一致 |
| @click | 点击某一屏时触发,回传被点项的下标 | Handler | - | 各端一致 |
| slot | 说明 |
|---|---|
| indicator | 自定义指示器;不填时按 indicator 开关渲染内置指示条 |
默认自动播放 :不传开关时挂载即自动轮播,默认三秒一换;只想放一张静图或需要用户手动滑时,要显式关掉自动播放。
22 · 默认档不铺满 :App 端默认裁剪档下图片只按固有宽度渲染,撑不满整屏、旁边露出底色;要整屏铺满得开 full,代价是图片被拉伸、不再保持比例。