diff --git a/packages/vant-cli/site/desktop/components/NavLink.vue b/packages/vant-cli/site/desktop/components/NavLink.vue index bc8157222..baf1cf748 100644 --- a/packages/vant-cli/site/desktop/components/NavLink.vue +++ b/packages/vant-cli/site/desktop/components/NavLink.vue @@ -35,6 +35,24 @@ export default { return false; } + }, + + watch: { + active() { + this.scrollIntoView(); + } + }, + + mounted() { + this.scrollIntoView(); + }, + + methods: { + scrollIntoView() { + if (this.active && this.$el && this.$el.scrollIntoViewIfNeeded) { + this.$el.scrollIntoViewIfNeeded(); + } + } } };