1. 程式人生 > >vueJS加jquery使用構建項目中v-model綁定的值無法清空

vueJS加jquery使用構建項目中v-model綁定的值無法清空

mode ace put pan 焦點 HA cti stat 事件

怎樣清空v-model綁定的input值緩存

在vue+bootstrap+jquery構架您的項目中,列表中formatter格式化單元格顯示的操作按鈕綁定bootstrap模態框,在模態框彈出的頁面中,用v-model綁定某個值後,點擊模態框有上角的關閉模態框按鈕,將模態框關閉掉,下一次點擊列表中操作按鈕,在模態框彈出後,頁面中的input輸入框在獲得並失去焦點以後會緩存上次的值。

在各種給綁定值賦空取法清空的時候:

1 <input type="text" id="aptTrain" class="form-control" placeholder="車次" v-model.trim="aptTrain" @change="queryTrain(‘endStation1‘)" @focus="clear">

可以給input加一個focus事件,判斷綁定的值是否為空,然後進行清空該值

 1 clear: function () {
 2                 var that = this;
 3                 // that.ticketGate = null;
 4                 // $(‘#ticketGate‘).val(‘‘);
 5                 if(that.ticketGate != null || that.ticketGate != ‘‘){
 6                     that.ticketGate = null
; 7 $(‘#ticketGate‘).val(‘‘); 8 }else{ 9 10 } 11 if(that.aptTrain != null || that.aptTrain != ‘‘){ 12 that.aptTrain = null; 13 $(‘#aptTrain‘).val(‘‘); 14 }else{ 15 16 }
17 18 }

vueJS加jquery使用構建項目中v-model綁定的值無法清空