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?
Vuex is a state management pattern for vue. js. $t is the injected method from vue. js or Vue. i18n.
One of Vue's most distinctive features is the unobtrusive reactivity system. Component state consists of reactive JavaScript objects. When you modify them, the view updates. It makes state management simple and intuitive, but it's also important to understand how it works to avoid some common gotchas.
observable transforms an object into a reactive entity. Vue uses this internally on the object returned by the data function. When changed, the resulting object can be directly utilized inside render functions and calculated properties, and it will trigger necessary modifications.
The Observer pattern works by one object — the observer — subscribing to another object — the subject — by way of a callback method. Whenever an event occurs on the subject, it notifies the observer that something happened.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With