admin管理员组

文章数量:1336311

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:

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:

So how can response.data.length be undefined?

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:

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:

So how can response.data.length be undefined?

Share Improve this question asked Dec 8, 2017 at 9:20 JenssenJenssen 1,8815 gold badges44 silver badges77 bronze badges 3
  • 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 Commented Dec 8, 2017 at 9:26
  • @Richard I can't read any properties from the object aswell they are all undefined any idea how I can fix this? – Jenssen Commented Dec 8, 2017 at 9:31
  • what do you get if you do console.log(response.data) – samayo Commented Dec 8, 2017 at 9:35
Add a ment  | 

1 Answer 1

Reset to default 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

本文标签: javascriptVuejs gives weird object with Observer dataStack Overflow