6

I'm receiving data with axios like this:

getData() {                                        
    Axios.get(                                        
        '/vue/get-data/',                           
        {                                             
            params: {                                 
                categories: this.category,            
                activeFilters: this.activeFilters,    
            }                                         
        }                                             
    ).then((response) => {                            
        this.banners = response.data;                 
        this.setBanner();                             
    })                                                
},           

Then I get this:

enter image description here

When I try console.log(response.data.length) I get undefined. What could be going on here very weird!

When I look in my vue-devtools banners has 2 objects:

enter image description here

So how can response.data.length be undefined?

Jenssen
  • 1,801
  • 4
  • 38
  • 72
  • `response.data` isn't a string (likely its a JS object read in from JSON). So have no `length` property. To see the RAW content try `JSON.stringify(response.data)`. – Richard Dec 08 '17 at 09:26
  • @Richard I can't read any properties from the object aswell they are all undefined any idea how I can fix this? – Jenssen Dec 08 '17 at 09:31
  • what do you get if you do console.log(response.data) – samayo Dec 08 '17 at 09:35

1 Answers1

5

You are getting object not array that why .length is not working, and you are getting as undefined

this.banners = response.data[0];// for first 

Or loop over this, to get each object's data

for(var i in response.data){
     console.log(response.data[i]);
}

If to get each value is not your purpose , and you want to just size check this answer

freelancer
  • 1,174
  • 5
  • 12
  • thanks but why do I see 2 object's in my vue devtools. Then I should be able to say .length right?! Because it's an array. – Jenssen Dec 08 '17 at 09:51