perf(ImagePreview): improve render perf

This commit is contained in:
陈嘉涵 2019-12-31 11:56:49 +08:00 committed by neverland
parent 0753ab03d0
commit b844a038fa

View File

@ -98,9 +98,12 @@ export default createComponent({
watch: { watch: {
value(val) { value(val) {
this.setActive(this.startPosition); if (val) {
this.setActive(this.startPosition);
if (!val) { this.$nextTick(() => {
this.$refs.swipe.swipeTo(this.startPosition, { immediate: true });
});
} else {
this.$emit('close', { this.$emit('close', {
index: this.active, index: this.active,
url: this.images[this.active] url: this.images[this.active]
@ -310,13 +313,13 @@ export default createComponent({
}, },
render() { render() {
if (!this.value) { if (!this.shouldRender) {
return; return;
} }
return ( return (
<transition name="van-fade"> <transition name="van-fade">
<div class={[bem(), this.className]}> <div vShow={this.value} class={[bem(), this.className]}>
{this.genImages()} {this.genImages()}
{this.genIndex()} {this.genIndex()}
{this.genCover()} {this.genCover()}