fix: change nextTick to onload for anchor scrolling (#1870)

* change nextTick to onload for anchor scrolling

* fix: handle anchor scrollTo if page already loaded

Co-authored-by: Nicolas Giard <github@ngpixel.com>
This commit is contained in:
Seyed Sajad Kahani 2020-05-11 21:33:47 +04:30 committed by GitHub
parent 4d14998859
commit 4d2d615402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -460,11 +460,19 @@ export default {
})
// -> Handle anchor scrolling
this.$nextTick(() => {
if (window.location.hash && window.location.hash.length > 1) {
this.$vuetify.goTo(window.location.hash, this.scrollOpts)
if (window.location.hash && window.location.hash.length > 1) {
if (document.readyState === 'complete') {
this.$nextTick(() => {
this.$vuetify.goTo(window.location.hash, this.scrollOpts)
})
} else {
window.addEventListener('load', () => {
this.$vuetify.goTo(window.location.hash, this.scrollOpts)
})
}
}
this.$nextTick(() => {
this.$refs.container.querySelectorAll(`a[href^="#"], a[href^="${window.location.href.replace(window.location.hash, '')}#"]`).forEach(el => {
el.onclick = ev => {
ev.preventDefault()