Skip to content

Instantly share code, notes, and snippets.

@enkot
Last active July 21, 2019 18:23
Show Gist options
  • Save enkot/2c95860716954df8230feb494cb08ca3 to your computer and use it in GitHub Desktop.
Save enkot/2c95860716954df8230feb494cb08ca3 to your computer and use it in GitHub Desktop.
// ...
<script>
import { fetchUserPosts } from '@/api'
export default {
props: {
id: Number
},
data() {
return {
isLoading: true,
pageOffset: 0,
posts: []
}
},
watch: {
id: {
handler: 'fetchPosts',
immediate: true
}
},
mounted() {
window.addEventListener('scroll', this.update)
},
destroyed() {
window.removeEventListener('scroll', this.update)
},
methods: {
async fetchPosts() {
this.isLoading = true
this.posts = await fetchUserPosts(this.id)
this.isLoading = false
},
update() {
this.pageOffset = window.pageYOffset
}
},
computed: {
count() {
return this.posts.length
}
}
}
</script>
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment