Answer the question
In order to leave comments, you need to log in
`
How to pull data in context for a page in nuxt js?
There is a request to yuoutub api
<script>
import axios from 'axios'
export default {
asyncData () {
return axios.get(`https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=50&key=AIzaSyBJy7U8AOb-7b7GH1NXW1vCXItADM`)
.then((res) => {
// return {videos: res.data.items}
console.log(res.data)
})
}
}
</script>
<template>
<div class="container">
<div class="list-items">
<VideoPreview
v-for = "video in videos"
:key = "video.id"
:id = "video.id"
:title = "video.snippet.title"
:thumbnailImage = "video.snippet.thumbnails.medium.url"
/>
</div>
</div>
</template>
Answer the question
In order to leave comments, you need to log in
I figured it out myself, I just had to write the request in the component like this:
<script>
import axios from 'axios'
export default {
asyncData ({ params }) {
return axios.get(`https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${params.id}&key=AIzaSyBJy7U8AOzPm7b7CXItADM`)
.then((res) => {
// return {videos: res.data.items}
console.log(res.data)
})
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question