bind:blur
失去焦點的時候,會調用這個事件,並且給自定義變量賦值
這樣在點按鈕的時候,最后一個輸入框,總是要提示沒有輸入值。
解決:
bind:change
只要有輸入,有改變就可以更新到變量,這樣就可以解決。
<van-field value="{{ phone }}" label="手機號" type="text" placeholder="請輸入手機號" required="true" data-fieldName="phone" bind:change="bindPhone" />
onChange:function(e) {
this.setData({ [e.currentTarget.dataset.prop]: e.detail })
},
bindPhone:function(e){
this.setData({phone:e.detail.value});
},
注意:
blur事件這個是
e.detail.value
在
change事件這個是
e.detail
否則獲取到的值是undefined