mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
This will allow us to use this.$scrollTo in components. I'm now also using this in the mixin. With so many `this`s it gets horribly difficult to properly test the mixin in isolation. So I decided to test the mixin on the component directly.
24 lines
554 B
JavaScript
24 lines
554 B
JavaScript
function scrollToAnchor(anchor, { checkAnchor, $scrollTo }) {
|
|
if (typeof checkAnchor !== 'function')
|
|
throw new Error(
|
|
'You must define `checkAnchor` on the component if you use scrollToAnchor mixin!',
|
|
)
|
|
if (!checkAnchor(anchor)) return
|
|
setTimeout(() => {
|
|
$scrollTo(anchor, 1000)
|
|
}, 250)
|
|
}
|
|
|
|
export default {
|
|
watch: {
|
|
$route(to, from) {
|
|
const anchor = to && to.hash
|
|
scrollToAnchor(anchor, this)
|
|
},
|
|
},
|
|
mounted() {
|
|
const anchor = this.$route && this.$route.hash
|
|
scrollToAnchor(anchor, this)
|
|
},
|
|
}
|