How to extract values from an event in Vue.js?

Viewed 186

Within Vue.js I am firing an event like this:

this.$emit("change", this.data);

The parent receives that data and every time the event is an object. But the event consists of values and an observer. For example:

{
  data: ['Joe Doe'],
  __ob__: Observer
}

How can I just keep grabbing all the values from an object and skip the __ob__ part?

1 Answers

Considering that an event is an object with data key, the payload can be accessed as event.data.

__ob__ is non-enumerable property used by Vue reactivity, it's displayed in dimmed color in console output:

ob

Non-enumerable keys are commonly ignored when object keys are indirectly accessed - for..in, Object.key, JSON.stringify, etc. __ob__ doesn't affect the way reactive object is used, unless the property is directly accessed, which shouldn't be done without valid reasons.

Related