代码之家  ›  专栏  ›  技术社区  ›  Sagar Kharche

dojo2中是否有渲染后生命周期挂钩?

  •  2
  • Sagar Kharche  · 技术社区  · 8 年前

    我在Dojo 2项目中工作。我知道Dojo 2上的项目不多,很难获得支持。无论如何,我在寻找渲染生命周期挂钩后的dojo 2小部件? 在React中,我们有:-

    componentDidMount: function() { console.log('Component rendered')},
    

    小部件呈现生命周期挂钩之后的dojo 2呢?

    2 回复  |  直到 7 年前
        1
  •  2
  •   agubler    8 年前

    这个 runAfterRenders 方法不打算被重写(实际上应该是 private )在小部件中。使用 @afterRender decorator是根据 readme

    class MyWidget extends WidgetBase {
    
        @afterRender()
        myAfterRender(vnode: VNode) {
             // do something with the resulting vnode
             vnode.children = [ ...vnode.children, 'Another Text Node' ];
    
             return vnode;
        }
    
    
        protected render() {
            return v('div', [ 'text' ]);
        }
    }
    

    这个 onAttach hook可能是与reacts更等效的生命周期 componentDidMount ,这是一个方法生命周期,其实现方式与 组件安装

    希望这有帮助!

        2
  •  1
  •   Sagar Kharche    8 年前

    我找到了解决方案: Dojo 2小部件具有runAfterRenders生命周期挂钩,可在渲染后触发。

    protected runAfterRenders(dNode: DNode | DNode[]): DNode | DNode[] { return dNode; }
    

    希望这会有所帮助。