美文网首页
ionic中的生命周期函数

ionic中的生命周期函数

作者: _Waiting_ | 来源:发表于2019-09-25 10:33 被阅读0次

    Ionic4 中内置的生命周期函数

    ionViewWillEnter —当进入一个页面时触发(如果它从堆栈返回)
    ionViewDidEnter —进入后触发
    ionViewWillLeave —如果页面将离开触发
    ionViewDidLeave — 在页面离开后触发
    ionViewWillUnload — 页面卸载的时候会触发,如果无法触发使用 ngOnDestroy

    ionViewDidLoad void Runs when the page has loaded. This event only happens once per page being created. If a page leaves but is cached, then this event will not fire again on a subsequent viewing. The ionViewDidLoad event is good place to put your setup code for the page.
    ionViewWillEnter void Runs when the page is about to enter and become the active page.
    ionViewDidEnter void Runs when the page has fully entered and is now the active page. This event will fire, whether it was the first load or a cached page.
    ionViewWillLeave void Runs when the page is about to leave and no longer be the active page.
    ionViewDidLeave void Runs when the page has finished leaving and is no longer the active page.
    ionViewWillUnload void Runs when the page is about to be destroyed and have its elements removed.
    ionViewCanEnter boolean/Promise<void> Runs before the view can enter. This can be used as a sort of "guard" in authenticated views where you need to check permissions before the view can enter
    ionViewCanLeave boolean/Promise<void> Runs before the view can leave. This can be used as a sort of "guard" in authenticated views where you need to check permissions before the view can leave

    Ionic4 可以使用的 Angular 生命周期函数

    ngOnChanges 当被绑定的输入属性的值发生变化时调用(父子组件传值的时候会触发
    ngOnInit 请求数据一般放在这个里面 (重要*)
    ngDoCheck 检测,并在发生 Angular 无法或不愿意自己检测的变化时作出反应
    ngAfterContentInit 当把内容投影进组件之后调用
    ngAfterContentChecked 每次完成被投影组件内容的变更检测之后调用
    ngAfterViewInit 初始化完组件视图及其子视图之后调用(dom 操作放在这个里面)(重 要)
    ngAfterViewChecked 每次做完组件视图和子视图的变更检测之后调用
    ngOnDestroy 组件销毁后执行 (重要)

    相关文章

      网友评论

          本文标题:ionic中的生命周期函数

          本文链接:https://www.haomeiwen.com/subject/nkgquctx.html