gpt4 book ai didi

ember.js - 如何调试 emberjs 计算属性

转载 作者:行者123 更新时间:2023-12-02 21:38:27 24 4
gpt4 key购买 nike

假设我有一个依赖于其他属性的计算属性。如何找出依赖属性的哪些更改会触发我的属性的重新计算。除此之外,还有什么方法可以调试计算链接吗?

最佳答案

如果您的计算属性位于组件中,您可以尝试 Hook didUpdateAttrs Hook 。当传递到组件的值更新时,didUpdateAttrs 会触发。在 didUpdateAttrs 中,您可以通过比较旧/新值来检查哪些属性发生了更改。

  didUpdateAttrs: function(attrs) {
// attrs should have access to the old/new values

}

https://guides.emberjs.com/v2.6.0/components/the-component-lifecycle/

didUpdateAttrs runs when the attributes of a component have changed, but not when the component is re-rendered, via component.rerender, component.set, or changes in models or services used by the template.

A didUpdateAttrs is called prior to rerender, you can use this hook to execute code when specific attributes are changed. This hook can be an effective alternative to an observer, as it will run prior to a re-render, but after an attribute has changed.

An example of this scenario in action is a profile editor component. As you are editing one user, and the user attribute is changed, you can use didUpdateAttrs to clear any error state that was built up from editing the previous user.

关于ember.js - 如何调试 emberjs 计算属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42531110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com