mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Swipe): add index when trigger onDragStart or onDragEnd (#11632)
* perf(Swipe): add index when trigger onDragStart or onDragEnd * perf(Swipe): change the arguments of the onDragStart and onDragEnd events to the Object --------- Co-authored-by: ZZQChongYa <zhengziqiang@star-net.cn>
This commit is contained in:
parent
c63fee0d13
commit
2d72821de0
@ -161,8 +161,8 @@ export default {
|
||||
| Event | Description | Arguments |
|
||||
| --- | --- | --- |
|
||||
| change | Emitted when current swipe changed | _index: number_ |
|
||||
| drag-start `v4.0.9` | Emitted when user starts dragging the swipe | - |
|
||||
| drag-end `v4.0.9` | Emitted when user ends dragging the swipe | - |
|
||||
| drag-start `v4.0.9` | Emitted when user starts dragging the swipe | _{ index: number }_ |
|
||||
| drag-end `v4.0.9` | Emitted when user ends dragging the swipe | _{ index: number }_ |
|
||||
|
||||
### SwipeItem Events
|
||||
|
||||
|
@ -166,11 +166,11 @@ export default {
|
||||
|
||||
### Swipe Events
|
||||
|
||||
| 事件名 | 说明 | 回调参数 |
|
||||
| ------------------- | ---------------------------- | --------------- |
|
||||
| change | 每一页轮播结束后触发 | _index: number_ |
|
||||
| drag-start `v4.0.9` | 当用户开始拖动轮播组件时触发 | - |
|
||||
| drag-end `v4.0.9` | 当用户结束拖动轮播组件时触发 | - |
|
||||
| 事件名 | 说明 | 回调参数 |
|
||||
| ------------------- | ---------------------------- | ------------------- |
|
||||
| change | 每一页轮播结束后触发 | _index: number_ |
|
||||
| drag-start `v4.0.9` | 当用户开始拖动轮播组件时触发 | _{ index: number }_ |
|
||||
| drag-end `v4.0.9` | 当用户结束拖动轮播组件时触发 | _{ index: number }_ |
|
||||
|
||||
### SwipeItem Events
|
||||
|
||||
|
@ -333,7 +333,7 @@ export default defineComponent({
|
||||
move({ offset: delta.value });
|
||||
|
||||
if (!dragging) {
|
||||
emit('dragStart');
|
||||
emit('dragStart', { index: activeIndicator.value });
|
||||
dragging = true;
|
||||
}
|
||||
}
|
||||
@ -377,7 +377,7 @@ export default defineComponent({
|
||||
dragging = false;
|
||||
state.swiping = false;
|
||||
|
||||
emit('dragEnd');
|
||||
emit('dragEnd', { index: activeIndicator.value });
|
||||
autoplay();
|
||||
};
|
||||
|
||||
|
@ -350,9 +350,13 @@ test('should emit drag-start and drag-end events correctly', async () => {
|
||||
|
||||
await triggerDrag(track, 100, 0);
|
||||
expect(dragStart).toHaveBeenCalledTimes(1);
|
||||
expect(dragStart).toHaveBeenCalledWith({ index: 0 });
|
||||
expect(dragEnd).toHaveBeenCalledTimes(1);
|
||||
expect(dragEnd).toHaveBeenCalledWith({ index: 1 });
|
||||
|
||||
await triggerDrag(track, 100, 0);
|
||||
expect(dragStart).toHaveBeenCalledTimes(2);
|
||||
expect(dragStart).toHaveBeenCalledWith({ index: 1 });
|
||||
expect(dragEnd).toHaveBeenCalledTimes(2);
|
||||
expect(dragEnd).toHaveBeenCalledWith({ index: 0 });
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user