`How to pull data in context for a page in nuxt js?
U
U
Uncle Deacon2018-03-31 15:40:43
Vue.js
Uncle Deacon, 2018-03-31 15:40:43

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>

After the request, I rendered video previews and brought them to the main page in this way
<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>

The question is how, in the context of this request, can I pull out the data for each video page?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Uncle Deacon, 2018-03-31
@Ezeneria

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>

And then, upon request, the necessary information will come

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question