diff --git a/docs/markdown/changelog.zh-CN.md b/docs/markdown/changelog.zh-CN.md index 3d7985d67..7e070fce3 100644 --- a/docs/markdown/changelog.zh-CN.md +++ b/docs/markdown/changelog.zh-CN.md @@ -19,6 +19,10 @@ - 支持`Number`类型的`input-width`属性 +##### SwipeCell + +- 修复只渲染单侧内容时报错的问题 + ##### Uploader - 新增`preview`属性 diff --git a/packages/swipe-cell/index.js b/packages/swipe-cell/index.js index ee175f139..fbe0abda6 100644 --- a/packages/swipe-cell/index.js +++ b/packages/swipe-cell/index.js @@ -31,25 +31,24 @@ export default sfc({ computed: { computedLeftWidth() { - if (this.leftWidth) { - return this.leftWidth; - } - - const rect = this.$refs.left.getBoundingClientRect(); - return rect.width; + return this.leftWidth || this.getWidthByRef('left'); }, computedRightWidth() { - if (this.rightWidth) { - return this.rightWidth; - } - - const rect = this.$refs.right.getBoundingClientRect(); - return rect.width; + return this.rightWidth || this.getWidthByRef('right'); } }, methods: { + getWidthByRef(ref) { + if (this.$refs[ref]) { + const rect = this.$refs[ref].getBoundingClientRect(); + return rect.width; + } + + return 0; + }, + open(position) { const offset = position === 'left' ? this.computedLeftWidth : -this.computedRightWidth; this.swipeMove(offset); diff --git a/packages/swipe-cell/test/__snapshots__/index.spec.js.snap b/packages/swipe-cell/test/__snapshots__/index.spec.js.snap index cd219a7f9..fc1b83429 100644 --- a/packages/swipe-cell/test/__snapshots__/index.spec.js.snap +++ b/packages/swipe-cell/test/__snapshots__/index.spec.js.snap @@ -53,3 +53,11 @@ exports[`drag and show right part 1`] = ` `; + +exports[`render one side 1`] = ` +