1

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?

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you clarify? If this.data is an object with data, and you need event listener to receive data only, it could be this.$emit("change", this.data.data). But this isn't related to __ob__, this key doesn't affect anything.
It makes sense now... I got confused the first time round due to storing incorrectly formatted event, due to which my tries using Object didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.