Skip to content

Commit a4f5f3a

Browse files
committed
fix: preview put zoom on preview when content type or url changes
1 parent 14c4486 commit a4f5f3a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

custom/preview.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
} */
5959
</style>
6060
<script setup>
61-
import { ref, computed , onMounted, watch} from 'vue'
61+
import { ref, computed , onMounted, watch, nextTick} from 'vue'
6262
import mediumZoom from 'medium-zoom'
6363
import { useRoute } from 'vue-router'
6464
@@ -141,14 +141,17 @@ function guessContentType(url) {
141141
}
142142
143143
144-
onMounted(async () => {
145-
146-
if (contentType.value?.startsWith('image')) {
144+
watch([url, contentType], async ([url, contentType]) => {
145+
if (zoom.value) {
146+
zoom.value.detach();
147+
}
148+
await nextTick();
149+
if (contentType?.startsWith('image')) {
147150
zoom.value = mediumZoom(img.value, {
148151
margin: 24,
149152
});
150153
}
151154
152-
});
155+
}, { immediate: true });
153156
154157
</script>

0 commit comments

Comments
 (0)