更新记录
0.0.4(2025-07-15) 下载此版本
0.0.4
0.0.3(2025-07-15) 下载此版本
增加回调
0.0.2(2025-07-13) 下载此版本
0.0.2
查看更多平台兼容性
uni-app(4.55)
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | - | √ | √ | √ |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
- | - | - | - | - | - | - | - | - | - | - |
uni-app x(4.55)
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | - | - | - | - |
q-cardFlyOut 卡片飞出组件
滑动卡片(Tinder 风格)组件,可支持 左右/上下 四个方向拖拽飞出,常用于推荐、刷卡等场景、类似于 探探 的交互风格。
快速开始
<template>
<view class="page">
<qCardFlyOut
ref="fly"
:list="cards"
:visible="3"
:thresholdRate="0.3"
:loadMoreOffset="4"
width="750rpx"
height="900rpx"
:directions="['left', 'right', 'up', 'down']"
@swipe="onSwipe"
@swipingLeft="onSwipingLeft"
@swipingRight="onSwipingRight"
@swipingUp="onSwipingUp"
@swipingDown="onSwipingDown"
@cancelLeft="onCancelLeft"
@cancelRight="onCancelRight"
@cancelUp="onCancelUp"
@cancelDown="onCancelDown"
@loadMore="onLoadMore"
@cardClick="onCardClick"
>
<!-- 默认插槽:卡片内容 -->
<template #default="{ item }">
<image :src="item.cover" mode="aspectFill" style="width: 100%; height: 100%; border-radius: 24rpx" />
</template>
<!-- footer 插槽:可放操作按钮等 -->
<template #footer>
<view class="btn-group">
<button @click="swipeLeft">左滑</button>
<button @click="swipeRight">右滑</button>
<button @click="swipeUp">上滑</button>
<button @click="swipeDown">下滑</button>
</view>
</template>
</qCardFlyOut>
</view>
</template>
<script>
import qCardFlyOut from '@/uni_modules/q-cardFlyOut/components/q-cardFlyOut/q-cardFlyOut.vue'
export default {
components: { qCardFlyOut },
data() {
return {
cards: []
};
},
created() {
this.cards = fetchCards(); // 拉取初始数据
},
methods: {
/* 回调示例 */
onSwipe({ direction, currentIndex, currentItem }) {},
onSwipingLeft(e) {},
onSwipingRight(e) {},
onSwipingUp(e) {},
onSwipingDown(e) {},
onCancelLeft(e) {},
onCancelRight(e) {},
onCancelUp(e) {},
onCancelDown(e) {},
onLoadMore() {},
onCardClick({ currentItem }) {},
/* 手动触发 */
swipeLeft() { this.$refs.fly.swipeLeft(); },
swipeRight() { this.$refs.fly.swipeRight(); },
swipeUp() { this.$refs.fly.swipeUp(); },
swipeDown() { this.$refs.fly.swipeDown(); }
}
};
</script>
📌 示例仅演示基本用法,实际请按需调整样式与交互逻辑。
Props
Prop | Type | Default | 说明 |
---|---|---|---|
list |
Array |
[] |
卡片数据列表,对象上 不会被组件改写,但会在其中临时添加 x 与 y 字段以记录位移。 |
visible |
Number |
5 |
同屏渲染的卡片数量,越大越流畅但越耗性能。 |
thresholdRate |
Number |
0.3 |
触发飞出的阈值,基于屏幕宽/高的比例。 |
loadMoreOffset |
Number |
5 |
当剩余卡片数量小于此值时触发 loadMore 事件(分页加载)。 |
width |
Number|String |
'100%' |
组件宽度,支持数值(px)或百分比、rpx 等。 |
height |
Number|String |
'100%' |
组件高度,同上。 |
directions |
Array<'left'|'right'|'up'|'down'> |
['left','right','up','down'] |
允许的滑动方向。 |
Events
事件名 | 触发时机 | 回调参数 |
---|---|---|
swipe |
每次卡片成功飞出后 | { direction, currentIndex, currentItem } |
swipingLeft / swipingRight / swipingUp / swipingDown |
正在拖动、尚未松手,分别对应方向 | { currentIndex, offsetX/offsetY, currentItem } |
cancelLeft / cancelRight / cancelUp / cancelDown |
松手但未超过阈值,卡片回弹 | { currentIndex, currentItem } |
loadMore |
剩余卡片数量 < loadMoreOffset 时 |
无 |
cardClick |
点击当前顶部卡片时 | { currentIndex, currentItem } |
Slots
Slot | 说明 |
---|---|
default | 必填。卡片内容,自带 item 、index 两个插槽 prop。 |
footer |
可选。卡片底部区域,通常放操作按钮。 |
方法
方法 | 说明 | 参数 |
---|---|---|
swipeLeft() |
主动将当前卡片向左飞出 | — |
swipeRight() |
主动将当前卡片向右飞出 | — |
swipeUp() |
主动将当前卡片向上飞出 | — |
swipeDown() |
主动将当前卡片向下飞出 | — |
manualSwipe(direction) |
根据入参方向飞出,direction 可为 'left'|'right'|'up'|'down' |
direction |
通过
ref
获取组件实例后调用上述方法,例如:this.$refs.fly.swipeLeft(); this.$refs.fly.manualSwipe('down');
样式定制
组件本身仅提供基础布局与过渡效果,大部分视觉样式请在插槽内实现,以便保持灵活性。
注意事项
- 组件会在原始
list
中注入临时字段x
、y
,若对此有顾虑请 deep copy 数据。 - 请勿在
list
中直接使用响应式ref
对象,推荐使用普通对象。 - 若卡片内容存在交互元素(按钮、链接等)需要阻止冒泡,请自行
@click.stop
处理。