生命周期

2.3.8版本之前请参考这里

:::tip 除了自有的生命周期钩子以外,
eeui还另外支持APP进入后台APP进入前台页面挂载页面激活页面失活页面停止。 :::

  1. <template>
  2. ...
  3. </template>
  4. <script>
  5. export default {
  6. beforeCreate: function (){
  7. console.log('beforeCreate');
  8. },
  9. created: function () {
  10. console.log('created');
  11. },
  12. beforeMount: function () {
  13. console.log('beforeMount');
  14. },
  15. mounted: function () {
  16. console.log('mounted');
  17. },
  18. beforeUpdate: function () {
  19. console.log('beforeUpdate');
  20. },
  21. updated: function () {
  22. console.log('updated');
  23. },
  24. beforeDestroy: function () {
  25. console.log('beforeDestroy');
  26. },
  27. destroyed: function () {
  28. console.log('destroyed');
  29. },
  30. appActive: function (data) {
  31. console.log('APP进入前台:App从【后台】切换至【前台】时触发');
  32. },
  33. appDeactive: function (data) {
  34. console.log('APP进入后台:App从【前台】切换至【后台】时触发');
  35. },
  36. pageReady: function (data) {
  37. console.log('页面挂载:页面【渲染完成】时触发');
  38. },
  39. pageResume: function (data) {
  40. console.log('页面激活:页面【恢复】时触发(渲染完成时也会触发1次)');
  41. },
  42. pagePause: function (data) {
  43. console.log('页面失活:页面【暂停】时触发');
  44. },
  45. pageDestroy: function (data) {
  46. console.log('页面停止:页面【销毁】时触发');
  47. }
  48. }
  49. </script>

生命周期钩子

Vue 组件的实例生命周期钩子将在特定的阶段发出,详情请参考 Vue 组件的生命周期图示

Vue 生命周期钩子 是否支持 说明
beforeCreate 支持 -
created 支持 -
beforeMount 支持 -
mounted 支持 详见下文解释
beforeUpdate 支持 -
updated 支持 -
activated 不支持 不支持<keep-alive>
deactivated 不支持 不支持<keep-alive>
beforeDestroy 支持 -
destroyed 支持 -
errorCaptured 支持 -
以下是eeui特有:
appActive 支持 APP进入前台:App从【后台】切换至【前台】时触发
appDeactive 支持 APP进入后台:App从【前台】切换至【后台】时触发
pageReady 支持 页面挂载:页面【渲染完成】时触发
pageResume 支持 页面激活:页面【恢复】时触发(渲染完成时也会触发1次)
pagePause 支持 页面失活:页面【暂停】时触发
pageDestroy 支持 页面停止:页面【销毁】时触发

::: warning 关于 “mounted” 生命周期

和浏览不同的是,eeui 的渲染流程是异步的,而且渲染出来的结果都是原生系统中的 View,这些数据都无法被 javascript 直接获取到。因此在 eeui 上,Vue 的 mounted 生命周期在当前组件的 virtual-dom (Vue 里的 VNode) 构建完成后就会触发,此时相应的原生视图未必已经渲染完成。 :::