Last active
July 21, 2019 18:23
-
-
Save enkot/2c95860716954df8230feb494cb08ca3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
<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