1.子组件被引用时,父组件如果以某一变量为子组件属性赋值,子组件需要根据赋值变换进而变化需要使用 name=“change” 的 handler
<!--parent-->
<aura:component>
<aura:attribute name="a" type="String"/>
<c:child childAttr="{!v.a}"/>
</aura:component>
<!--child-->
<aura:component>
<aura:attribute name="childAttr" type="String"/>
<aura:handler name="change" value="{!v.childAttr}" action="{!c.showAttr}"/>
<!--Do not use name="init"-->
</aura:component>
<script>
// child controller
({
showAttr:function (cmp, event, helper) {
console.log(cmp.get('v.childAttr'));// every time you changed childAttr, it shows.
}
})
</script>
2.当lightning中使用input标签type=“date”时,若要指定默认值需要默认固定格式的字符串,如:
<aura:component>
<aura:attribute name="today" type="Date"/>
<aura:handler action="{!c.init}" value="{!this}" name="init"/>
<lightning:input label="Date" name="date" value="{!v.today}"/> <!--show today date-->
<lightning:input label="Date" name="date" value="{!'2018-8-15'}"/>
</aura:component>
<script>
// controller
({
init:function (cmp, event, helper) {
var today = new Date((new Date().getTime()));
var monthDigit = today.getMonth() + 1;
if (monthDigit <= 9) {
monthDigit = '0' + monthDigit;
}
component.set('v.deadLine', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());
}
})
</script>