[bugfix] SwipeCell: should ensure ref exist before get width

This commit is contained in:
陈嘉涵
2019-06-05 10:03:47 +08:00
parent 5dee1eb22f
commit 351e642e6d
4 changed files with 41 additions and 12 deletions

View File

@@ -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);