Skip to content

Instantly share code, notes, and snippets.

@eladcandroid
Forked from enkot/scrollSetupComponent.vue
Last active March 30, 2020 02:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eladcandroid/75c9dbaf13d80602b4636b1060d09757 to your computer and use it in GitHub Desktop.
Save eladcandroid/75c9dbaf13d80602b4636b1060d09757 to your computer and use it in GitHub Desktop.
Change to Vue Composition Api
// ...
<script>
import { ref, onMounted, onUnmounted } from '@vue/composition-api'
export default {
setup(props) {
const pageOffset = ref(0)
const update = () => {
pageOffset.value = window.pageYOffset
}
onMounted(() => window.addEventListener('scroll', update))
onUnmounted(() => window.removeEventListener('scroll', update))
return {
pageOffset
}
}
}
</script>
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment