mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
[bugfix] SwipeCell: should ensure ref exist before get width
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user