Skip to content

Commit

Permalink
fix: image zoom not work after route changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lvqq committed May 19, 2023
1 parent 3e8a3b5 commit 478a29a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/.vitepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import DefaultTheme from 'vitepress/theme';
import { onMounted } from 'vue';
import { onMounted, watch, nextTick } from 'vue';
import mediumZoom from 'medium-zoom';
import { useRoute } from 'vitepress';
import './index.css';

export default {
...DefaultTheme,
setup() {
onMounted(() => {
const route = useRoute();
const initZoom = () =>
mediumZoom('.main img', { background: 'var(--vp-c-bg)' });
onMounted(() => {
initZoom();
});
watch(
() => route.path,
() => nextTick(() => initZoom())
);
},
};

0 comments on commit 478a29a

Please sign in to comment.