前端框架Aurelia

来源:互联网 发布:淘宝二手货 编辑:程序博客网 时间:2024/04/28 14:10
import {computedFrom} from 'aurelia-framework';export class Person {  firstName: string = 'John';  lastName: string = 'Doe';  @computedFrom('firstName', 'lastName')  get fullName(): string {    return `${this.firstName} ${this.lastName}`;  }}


@computedFrom tells the binding system which expressions to observe. When those expressions change, the binding system will re-evaluate the property (execute the getter). This eliminates the need for dirty checking and can improve performance. The @computedFrom parameters can be simple property names as shown above or more complex expressions like @computedFrom('event.startDate', 'event.endDate').


@computedFrom告诉binding system哪个表达式需要去观察。

当这个表达式change的时候,binding system需要重新计算properties。(执行getter)

避免了频繁的检查,避免的大数据量和大计算量的check。

@ComputedFrom参数可以是简单的属性名字就像上面示例,或者是更加复杂的表达式。


0 0
原创粉丝点击