diff --git a/packages/cell-swipe/en-US.md b/packages/cell-swipe/en-US.md index 31cc1b3ef..f0543c316 100644 --- a/packages/cell-swipe/en-US.md +++ b/packages/cell-swipe/en-US.md @@ -73,7 +73,17 @@ export default { | right | content of right scrollabe area | ### onClose Params + | Argument | Type | Description | |-----------|-----------|-----------| | clickPosition | `String` | Click positon (`left` `right` `cell` `outside`) | -| instance | `Object` | CellSwipe instance with a close method | +| instance | `Object` | CellSwipe instance | + +### Methods + +Use ref to get CellSwipe instance and call instance methods + +| Name | Attribute | Return value | Description | +|-----------|-----------|-----------|-------------| +| open | position: 'left' \| 'right' | - | open CellSwipe | +| close | - | - | close CellSwipe | diff --git a/packages/cell-swipe/index.vue b/packages/cell-swipe/index.vue index 02d7f64e4..8b451a002 100644 --- a/packages/cell-swipe/index.vue +++ b/packages/cell-swipe/index.vue @@ -69,6 +69,12 @@ export default create({ }, methods: { + open(position) { + const offset = position === 'left' ? this.leftWidth : -this.rightWidth; + this.swipeMove(offset); + this.resetSwipeStatus(); + }, + close() { this.offset = 0; }, @@ -90,12 +96,10 @@ export default create({ // right if (direction > 0 && -offset > rightWidth * threshold && rightWidth > 0) { - this.swipeMove(-rightWidth); - this.resetSwipeStatus(); + this.open('right'); // left } else if (direction < 0 && offset > leftWidth * threshold && leftWidth > 0) { - this.swipeMove(leftWidth); - this.resetSwipeStatus(); + this.open('left'); } else { this.swipeMove(); } diff --git a/packages/cell-swipe/zh-CN.md b/packages/cell-swipe/zh-CN.md index 72724c0b0..16a069a9a 100644 --- a/packages/cell-swipe/zh-CN.md +++ b/packages/cell-swipe/zh-CN.md @@ -73,7 +73,17 @@ export default { | right | 右侧滑动内容 | ### onClose 参数 + | 参数 | 类型 | 说明 | |-----------|-----------|-----------| | clickPosition | `String` | 关闭时的点击位置 (`left` `right` `cell` `outside`) | -| instance | `Object` | CellSwipe 实例,挂载有 close 方法 | +| instance | `Object` | CellSwipe 实例 | + +### 方法 + +通过 ref 可以获取到 CellSwipe 实例并调用实例方法 + +| 方法名 | 参数 | 返回值 | 介绍 | +|-----------|-----------|-----------|-------------| +| open | position: 'left' \| 'right' | - | 打开单元格侧边栏 | +| close | - | - | 收起单元格侧边栏 |