mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-26 00:09:15 +08:00
chore(ImagePreview): optimize event binding
This commit is contained in:
parent
b66597621c
commit
5fff24cee8
@ -99,7 +99,10 @@ export default createComponent({
|
|||||||
watch: {
|
watch: {
|
||||||
value(val) {
|
value(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.onShow();
|
this.setActive(this.startPosition);
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$refs.swipe.swipeTo(this.startPosition, { immediate: true });
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$emit('close', {
|
this.$emit('close', {
|
||||||
index: this.active,
|
index: this.active,
|
||||||
@ -108,29 +111,13 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
startPosition(active) {
|
startPosition(val) {
|
||||||
this.setActive(active);
|
this.setActive(val);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
shouldRender: {
|
||||||
if (this.value) {
|
handler(val) {
|
||||||
this.bindEvent();
|
if (val) {
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
onShow() {
|
|
||||||
this.bindEvent();
|
|
||||||
this.setActive(this.startPosition);
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.$refs.swipe.swipeTo(this.startPosition, { immediate: true });
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
bindEvent() {
|
|
||||||
if (!this.eventBinded) {
|
|
||||||
this.eventBinded = true;
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const swipe = this.$refs.swipe.$el;
|
const swipe = this.$refs.swipe.$el;
|
||||||
on(swipe, 'touchstart', this.onWrapperTouchStart);
|
on(swipe, 'touchstart', this.onWrapperTouchStart);
|
||||||
@ -140,7 +127,11 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
onWrapperTouchStart() {
|
onWrapperTouchStart() {
|
||||||
this.touchStartTime = new Date();
|
this.touchStartTime = new Date();
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user