Javascript Vuejs,获取$event.emit的内容

Javascript Vuejs,获取$event.emit的内容,javascript,vue.js,vue-events,Javascript,Vue.js,Vue Events,我正在尝试获取$event.emit的内容,如下所示。在第一个console.log中,函数中包含内容。离开函数,而不是变量的console.log mounted () { this.$events.on('emitEvent', function (eventData) { this.line = _.cloneDeep(eventData) console.log('1', this.line) }) console.log('2', this.line) }

我正在尝试获取$event.emit的内容,如下所示。在第一个console.log中,函数中包含内容。离开函数,而不是变量的console.log

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

我正在使用它进行事件处理。

尝试这样做:

mounted() {
   var $that = this;

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

   console.log('2', this.line);
}
这应该起作用:

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

这是什么
console.log('1,this.line)
?在第一个console.log中,显示对象的内容。在第二个console.log中,函数失效,不向我返回任何内容,您只输入了一个引号。这是故意的吗?这里的
上下文与vue组件不同。所以要访问您的数据属性,您可以使用闭包而不是functionAre?据我所知,默认Vue实例中没有
$events
对象。。。