【问题标题】:Aurelia and computed propertiesAurelia 和计算属性
【发布时间】:2015-11-10 09:33:51
【问题描述】:

我刚开始研究 AureliaJS,所以我创建了一个示例应用程序,描述如下:http://aurelia.io/get-started.html。我注意到那里有一种奇怪的行为。

在我们的例子中:

get fullName(){
    return `${this.firstName} ${this.lastName}`;
}

但是当我把日志放在那里时:

get fullName(){
    console.log('test');
    return `${this.firstName} ${this.lastName}`;
}

应用程序将开始无限记录“测试”值。你有过同样的结果吗?

【问题讨论】:

    标签: javascript aurelia


    【解决方案1】:

    我刚刚在这里经历了一次脏检查。当我们使用计算属性时,我们必须明确定义依赖关系。像这样:

    @computedFrom('firstName', 'lastName')
    get fullName(){
        return `${this.firstName} ${this.lastName}`;
    }
    

    如果您没有在此处指定 computedFrom 装饰器,aurelia 将使用脏检查。

    【讨论】:

      猜你喜欢
      • 2015-11-08
      • 2015-11-16
      • 2011-01-15
      • 2017-08-26
      • 2017-12-18
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多