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?
-
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
本文标签: javascriptVuejs gives weird object with Observer dataStack Overflow
版权声明:本文标题:javascript - Vue.js gives weird object with Observer data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742323619a2453287.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论