Skip to content

Instantly share code, notes, and snippets.

@enkot
Last active August 2, 2019 10:24
Show Gist options
  • Save enkot/e29d5c47e4231239036d9f0f51ceb62b to your computer and use it in GitHub Desktop.
Save enkot/e29d5c47e4231239036d9f0f51ceb62b to your computer and use it in GitHub Desktop.
// ...
<script>
import { value, onMounted, onUnmounted } from 'vue-function-api'
export default {
setup(props) {
const pageOffset = value(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