diff --git a/packages/@vuepress/plugin-active-header-links/mixin.js b/packages/@vuepress/plugin-active-header-links/mixin.js index 0f7865878b..1d25143025 100644 --- a/packages/@vuepress/plugin-active-header-links/mixin.js +++ b/packages/@vuepress/plugin-active-header-links/mixin.js @@ -68,8 +68,12 @@ export default { methods: { onScroll: throttle(function () { + const anchors = getAnchors() + if (anchors.length === 0) { + return + } this.$lastAnchor = this.$currentAnchor - this.$currentAnchor = calculateCurrentAnchor(getAnchors()) + this.$currentAnchor = calculateCurrentAnchor(anchors) if (!this.$lastAnchor || this.$lastAnchor.hash !== this.$currentAnchor.hash) { this.$vuepress.$emit('AnchorHashChange', this.$currentAnchor) }