From 6929b04d56ab55344ba3abab85ef818b008eb889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Thu, 12 Dec 2019 20:53:32 +0800 Subject: [PATCH] feat(cli): improve nav scroll position --- .../site/desktop/components/NavLink.vue | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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(); + } + } } };