Is it possible to emit from mounted in Vuejs?

女生的网名这么多〃 提交于 2019-12-02 11:55:49

When you add an event handler in the parent's mounted lifecycle event for an event that is emitted in a child's mounted event, the handler will not catch the event emitted by the child because the handler is added after the child has already emitted the event. Basically the cycle of events is like this.

  1. Parent's create
  2. Child's create
  3. Child's mounted
  4. Parent's mounted

Obviously there are other lifecycle events that occur, but that's the sequence that matters in this case.

If you want to handle an event emitted in the child, you need to create the handler (call $on) before the child's mounted event.

This may also be useful, it solved one of my issues. :)

$nextTick

It's used like that.

mounted: function () {
  this.$nextTick(function () {
    // Code that will run only after the
    // entire view has been rendered
  })
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!