diff --git a/src/image-preview/test/__snapshots__/index.spec.js.snap b/src/image-preview/test/__snapshots__/index.spec.js.snap
index 5ac20fc5b..b4c5692e2 100644
--- a/src/image-preview/test/__snapshots__/index.spec.js.snap
+++ b/src/image-preview/test/__snapshots__/index.spec.js.snap
@@ -4,7 +4,7 @@ exports[`close-icon prop 1`] = `
1 / 0
Custom Cover Content
@@ -33,7 +33,7 @@ exports[`cover slot 1`] = `
exports[`index slot 1`] = `
@@ -55,7 +55,7 @@ exports[`render image 1`] = `
exports[`set show-index prop to false 1`] = `
`;
diff --git a/src/swipe/index.js b/src/swipe/index.js
index 01873c39d..95816beea 100644
--- a/src/swipe/index.js
+++ b/src/swipe/index.js
@@ -149,31 +149,25 @@ export default createComponent({
},
mounted() {
- this.initRect();
this.bindTouchEvent(this.$refs.track);
},
methods: {
- initRect() {
- this.rect = this.$el.getBoundingClientRect();
- },
-
// initialize swipe position
initialize(active = +this.initialSwipe) {
- if (!this.rect) {
+ if (!this.$el || isHidden(this.$el)) {
return;
}
clearTimeout(this.timer);
- if (this.$el && !isHidden(this.$el)) {
- const { rect } = this;
- this.computedWidth = Math.round(+this.width || rect.width);
- this.computedHeight = Math.round(+this.height || rect.height);
- }
+ const rect = this.$el.getBoundingClientRect();
+ this.rect = rect;
this.swiping = true;
this.active = active;
+ this.computedWidth = Math.round(+this.width || rect.width);
+ this.computedHeight = Math.round(+this.height || rect.height);
this.offset = this.getTargetOffset(active);
this.children.forEach((swipe) => {
swipe.offset = 0;
@@ -183,7 +177,6 @@ export default createComponent({
// @exposed-api
resize() {
- this.initRect();
this.initialize(this.activeIndicator);
},