-
-
Save eladcandroid/dbb0ecacacab91af452ecb3c2ee2dc83 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 { | |
value, | |
watch, | |
computed, | |
onMounted, | |
onUnmounted | |
} from 'vue-function-api' | |
import { fetchUserPosts } from '@/api' | |
export default { | |
setup(props) { | |
const pageOffset = value(0) | |
const isLoading = value(false) | |
const posts = value([]) | |
const count = computed(() => posts.value.length) | |
const update = () => { | |
pageOffset.value = window.pageYOffset | |
} | |
onMounted(() => window.addEventListener('scroll', update)) | |
onUnmounted(() => window.removeEventListener('scroll', update)) | |
watch( | |
() => props.id, | |
async id => { | |
isLoading.value = true | |
posts.value = await fetchUserPosts(id) | |
isLoading.value = false | |
} | |
) | |
return { | |
isLoading, | |
pageOffset, | |
posts, | |
count | |
} | |
} | |
} | |
</script> | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment