所以,如果你想给一个Vue组件添加生命周期函数有3个办法:

  • Vue组件选项中添加;
  • 在模板中通过@hooks:created这种形式;
  • vm.$on('hooks:created', cb)或者 vm.$once('hooks:created', cb)