我正在接收这样的axios数据:
getData() {
Axios.get(
'/vue/get-data/',
{
params: {
categories: this.category,
activeFilters: this.activeFilters,
}
}
).then((response) => {
this.banners = response.data;
this.setBanner();
})
}, 那我就明白了:

当我尝试console.log(response.data.length)时,我得到了undefined。这里会发生什么很奇怪的事!
当我查看我的vue-devtools横幅时,有两个对象:

那么,response.data.length怎么可能是未定义的呢?
发布于 2017-12-08 09:37:23
您得到的是对象而不是数组,这是为什么.length不能工作的原因,并且您得到的是undefined
this.banners = response.data[0];// for first 或者循环处理,以获取每个对象的数据
for(var i in response.data){
console.log(response.data[i]);
}如果to get每个值都不是您的目的,并且您只想调整大小,请检查此answer
https://stackoverflow.com/questions/47711134
复制相似问题