Skip to content

Swiper 轮播图 ​

uvx-swiper 展示图片或视频轮播列表,支持自动播放、循环、垂直方向、多项展示和指标器。

平台兼容性 ​

AndroidiOS鸿蒙H5微信
3.9+4.11+4.61+4.0+4.41+

基础用法 ​

vue
<template>
   <uvx-swiper
      :list="images"
      :autoplay="true"
      :indicator="true"
      @change="handleChange"
   ></uvx-swiper>
</template>

<script lang="uts" setup>
import type { ChangeEvent, Item } from "@/uni_modules/uvx-ui/components/uvx-swiper/types/index.uts";

const images: Item[] = [
   "https://picsum.photos/750/400?random=1",
   "https://picsum.photos/750/400?random=2",
   "https://picsum.photos/750/400?random=3",
];

const handleChange = (event: ChangeEvent): void => {
   console.log("current index", event.current);
};
</script>

list 也可以传对象数组;配合 key-name 指定图片地址字段。对象中设置 type: "video" 时会按视频项处理,并建议关闭自动播放。

API ​

Props ​

属性说明类型默认值
list图片地址或对象数据(string | UTSJSONObject)[][]
indicator是否显示指标器booleanfalse
indicator-active-color / indicator-inactive-color指标器激活和未激活颜色string""
indicator-style / indicator-mode指标器样式和模式string"" / line
autoplay / circular自动播放和循环booleantrue / false
current / current-item-id当前项索引和标识string | number / string0 / ""
interval / duration自动播放间隔和动画时长,单位 msstring | number3000 / 300
vertical是否垂直方向booleanfalse
previous-margin / next-margin前后露出边距string | number0
acceleration是否开启加速booleanfalse
display-multiple-items同时显示的轮播项数量number1
easing-function滑动动画缓动函数EasingFunctiondefault
key-name对象数据中的图片地址字段stringurl
img-mode图片裁剪模式ImageModeaspectFill
height / radius高度和圆角string | number130 / 4
bg-color背景颜色string""
loading是否显示加载状态booleanfalse
show-title / title-style是否显示标题及样式boolean / stringfalse / ""
u-style / u-class自定义样式和类名string""

Events ​

事件说明参数
click点击轮播项item: Item, index: number
change当前项变化ChangeEvent(current, currentItemId, source)

轮播项点击回调接收两个参数,不能只按事件对象读取:

uts
const handleClick = (item: Item, index: number): void => {
   console.log(item, index);
};

Slots ​

名称说明
indicator自定义指标器内容;使用后替换内置指标器

参考 ​

uvx-ui · uni-app x 组件库