更新记录

0.0.1(2026-06-13) 下载此版本


平台兼容性

uni-app(5.0)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
- - - - - - - - -
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - -

y-swiper

纵向虚拟滑动容器:固定 size 个 DOM 槽位(.y-swiper-main)映射 list 数据;手势上滑下一项、下滑上一项;v-model 绑定当前数据索引。


快速用法

<y-swiper v-model="currentIndex" :list="dataList" @need="onNeed">
  <template #default="{ item, index, swiper }">
    <view class="slide">{{ item?.content }}</view>
  </template>
</y-swiper>
  • v-model:当前数据在 list 中的索引(number)。
  • list:数据源;为空时不响应滑动。
  • size:同时存在的 DOM 槽位数,默认 4(建议 ≥2)。
  • min:剩余条数等于该值时,上滑切到下一项触发 need
  • scoped 插槽item(数据项,越界为 null)、index(数据索引)、swiper(槽位索引)。

Props

属性 类型 默认值 说明
modelValue Number 0 当前数据索引,需 v-model
list Array [] 数据列表
size Number 4 缓存 DOM 槽位数
min Number 3 剩余条数等于该值时触发 need

事件

事件 参数 说明
update:modelValue number 切换项后的新索引
change number 同 update:modelValue,切换项后的新索引
top 已在首项时继续下滑
bottom 已在末项时继续上滑
need 上滑后剩余条数等于 min,每轮 list.length 变化仅触发一次

行为说明

  • 根节点 .y-swiper 监听 touch;touchmove 使用 .stop.prevent 禁用橡皮筋。
  • 位移以容器高度换算为 translateY 百分比;松手阈值:普滑 50%、快速滑动 8%(600ms 内再次触摸判定快速滑)。
  • 首/末项边界:拖动阻尼(约 10%);越界滑动 emit top / bottom,不切换索引。
  • size === 2size > 2 使用不同的槽位映射算法(getItemByRenderIndex)。
  • 切换项时更新 currentIndex(槽位轮转)并 emit update:modelValuechange
  • need 条件:list.length - modelValue - 1 === min 时在上滑切项后触发;list.length 变化会重置触发标志。
  • 无 Ref 暴露方法;父级仅改 modelValue 会更新插槽数据映射,槽位视觉位置以内部 currentIndex 为准。

使用注意

  • 默认容器高度 90vh,挂载后测量实际高度参与位移计算。
  • item 可能为 null(槽位映射到越界索引时),模板中请做空值判断。

样式自定义

y-swiper
  y-swiper-main(y-swiper-animation)
    默认 scoped 插槽内容
<y-swiper v-model="i" :list="list" class="my-swiper">
  <template #default="{ item }">
    <view class="slide">{{ item?.title }}</view>
  </template>
</y-swiper>

<style lang="scss" scoped>
.my-swiper :deep(.y-swiper) {
  height: 80vh;
  .y-swiper-main { border-radius: 16rpx; }
}
</style>

示例

加载更多(need)

<y-swiper v-model="index" :list="list" :min="3" @need="loadMore" />

双槽模式

<y-swiper v-model="index" :list="list" :size="2">
  <template #default="{ item, index }">
    <view>{{ index }} — {{ item?.content }}</view>
  </template>
</y-swiper>

边界事件

<y-swiper v-model="index" :list="list" @top="onTop" @bottom="onBottom" />

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。