1
0
Fork 0

chore: move video list loading

This commit is contained in:
Ava Gaiety Wroten 2021-12-29 01:11:01 -06:00
parent c818225ccb
commit 322622909a
2 changed files with 24 additions and 30 deletions

View file

@ -22,8 +22,29 @@ import Vue from 'vue'
export default Vue.extend({ export default Vue.extend({
name: 'VideoList', name: 'VideoList',
props: { data(): {
videos: Array, hasError: boolean
videos: []
} {
return {
hasError: false,
videos: [],
}
}, },
async fetch() {
try {
const response = await fetch(
`https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId=${process.env.YOUTUBE_UPLOADS_PLAYLIST_ID}&key=${process.env.YOUTUBE_API_KEY}`
)
const json = await response.json()
this.videos = json.items
} catch (error: any) {
this.hasError = true
throw new Error(error)
}
},
fetchOnServer: true,
}) })
</script> </script>

View file

@ -4,9 +4,7 @@
<PageNav /> <PageNav />
</header> </header>
<main> <main>
<span>Content</span> <VideosList />
<VideosList :videos="videos" />
</main> </main>
</div> </div>
</template> </template>
@ -16,30 +14,5 @@ import Vue from 'vue'
export default Vue.extend({ export default Vue.extend({
name: 'IndexPage', name: 'IndexPage',
data(): {
hasError: boolean
videos: []
} {
return {
hasError: false,
videos: [],
}
},
async fetch() {
try {
const response = await fetch(
`https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=50&playlistId=${process.env.YOUTUBE_UPLOADS_PLAYLIST_ID}&key=${process.env.YOUTUBE_API_KEY}`
)
const json = await response.json()
this.videos = json.items
} catch (error: any) {
this.hasError = true
throw new Error(error)
}
},
fetchOnServer: true,
}) })
</script> </script>