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?
-
response.data
isn't a string (likely its a JS object read in from JSON). So have nolength
property. To see the RAW content tryJSON.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
1 Answer
Reset to default 5You 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742323619a4422312.html
评论列表(0条)