import Vue from 'vue'
-const maxResults: number = 2
export default Vue.extend({
name: 'VideoList',
- data(): {
- hasError: boolean
- videos: []
- } {
- return {
- hasError: false,
- videos: [],
- }
+ props: {
+ videos: {
+ type: Array,
+ default: () => {
+ return []
+ },
+ required: true,
+ },
},
-
- async fetch() {
- try {
- const response = await fetch(
- `https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=${maxResults}&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,
})
diff --git a/nuxt.config.js b/nuxt.config.js
index a131a66..2c04445 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -112,6 +112,10 @@ export default {
],
},
+ router: {
+ routes: [{ path: '/:pageToken', props: true }],
+ },
+
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
diff --git a/pages/index.vue b/pages/index.vue
index c9fdb25..abc2d59 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -6,8 +6,17 @@
-
-
+
+
Fetching videos...
+
An error occurred :(
+
+
+
+
+