[Vuejs]-How can i access to 'download_url' in json using vuejs

0👍

Assuming that response.data.items is the json you showed above, you can extract just what you want from there. Right now, your component has the whole response.data.items in this.response. So if you want all of it there, keep that.
You can store the ‘tags’ and ‘download url’ to your component by adding two new pieces of data ie add them to your data:

  data () {
    return {
      results: null,
      tags: null,
      downloadUrl: null
    }

… and then set those in your response block from the request’s response like this.

  mounted () {
    axios.get('http://127.0.0.1:8000/api/v2/pages/?type=news.NewsPage&fields=intro,body,image_thumbnail')
      .then((response) => (

        this.results = response.data.items
        this.tags = response.data.items.meta.tags
        this.downloadUrl = response.data.items.download_url

      ))
  }

When dealing with nested response objects like this, it can help to make a local variable with the data and add it that way. Also, if you dont need the whole response, you can avoid storing it and just store the data from the response that you want to your component here. If you wanted to get something from your this.response, you’re going to have to go deep into it. It would be cleaner to just pull out only what you need, and then use it in your code with just one {{myStuffIPulledOut}} vs {{response.thingIWantBefore.actualThing.}}

Leave a comment