如果我的子控件(本例中为孙辈控件)如下所示:
<my-control region-id.two-way="location.regionId"></my-control>
我什么时候可以期待 regionId 有空吗?这些文档听起来像是绑定,然后又附加了,所以不应该这样
regionId
bind attached regionIdChanged 看看控制台,我明白了
bind
attached
regionIdChanged
bind attached regionIdChange to null from undefined (default value in a dropdown) regionIdChange to 1 from null (1 is the actual value)
我早就料到了 regionId 1岁之前 附属的
附属的
变量应填入 bind()
bind()
如果将日志记录添加到每个阶段:
export class Child { @bindable() public field: string; constructor() { console.info("constructor: ", this.field); } bind() { console.info("bind: ", this.field); } attached() { console.info("attached: ", this.field); } }
它生成以下日志输出:
constructor: undefined bind: test attached: test
哪里 test 是我绑定的值。
test