0

I'm trying to get the content of a $event.emit, as below. In the first console.log, inside the function comes the content. Leaving the function, not the console.log of the variable.

mounted () {
  this.$events.on('emitEvent', function (eventData) {
    this.line = _.cloneDeep(eventData)
    console.log('1', this.line)
  })
  console.log('2', this.line)
}

I am using this package for event handling.

Vince
  • 3,207
  • 1
  • 17
  • 28
usr123123
  • 21
  • 5

2 Answers2

0

Try doing it like this:

mounted() {
   var $that = this;

   this.$events.on('emitEvent', function (eventData) {
        $that.line = _.cloneDeep(eventData);
        console.log('1', $that.line);
   })

   console.log('2', this.line);
}
T. Short
  • 3,481
  • 14
  • 30
0

this should work:

this.$events.on('emitEvent', (eventData) => {
    this.line = _.cloneDeep(eventData)
    console.log('1', this.line)
  })
  console.log('2', this.line)
 }