Skip to content

Commit

Permalink
feat: use scrolltoHash function instead of router.scrollBehavior func…
Browse files Browse the repository at this point in the history
…tion for jumplinks
  • Loading branch information
tikagan committed Jul 9, 2023
1 parent c5cf902 commit c344c7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
32 changes: 0 additions & 32 deletions app/router.scrollBehavior.js

This file was deleted.

27 changes: 26 additions & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@

<script>
export default {
name: 'LayoutDefault'
name: 'LayoutDefault',
watch: {
'$route.hash' () {
this.scrollToHash()
}
},
mounted () {
// Scroll to hash
this.$nextTick(() => {
this.scrollToHash()
})
},
methods: {
scrollToHash () {
const hash = this.$route.hash.replace('#', '')
if (hash) {
const element = document.getElementById(hash) || document.querySelector(`[data-id='${hash}']`)
if (element) {
this.$scrollToElement(element, 200, -100)
}
}
}
}
}
</script>

0 comments on commit c344c7b

Please # to comment.