2017-06-05 62 views
0

我使用的部件事先鍵入的內容從VUE錶帶,VueJS 2鍵盤緩衝回調方法

我試圖做一個回調,我打將在其上的數據戳在我的文字輸入後選擇。

一旦我打回車,inventoryName和inventoryId被成功加蓋,但inventoryCode組件被重置。

如何防止它重置或我做錯了什麼?正如我從console.log中看到的那樣,它具有價值。

<typeahead v-model="inventoryCode" placeholder="Inventory code..." async="{{url('api/inventory')}}/" :template="inventorySearch" :on-hit="inventoryCallBack"></typeahead> 
<input type="text" name="inventory_name" id="inventory_name" class="form-control" v-model="inventoryName" readonly /> 

new Vue({ 
     el: '#app', 
     components:{Typeahead}, 
     data: { 
      'inventoryCode': '', 
      'inventoryName': '', 
      'inventoryId': '', 
      'inventorySearch': '<div style="min-width:150px;"><b>@{{item.inventory_name}}</b></div><div>@{{item.inventory_code}}</div><div>@{{item.inventory_short_desc}}</div>' 
     }, 
methods:{ 
    inventoryCallBack: function(item){ 
        console.log(item.inventory_code); 
        this.inventoryCode = item.inventory_code; 
        this.inventoryName = item.inventory_name; 
        this.inventoryId = item.id; 
        console.log(this.inventoryCode); 
       }, 
} 
}); 
+0

首先'inventoryCallBack'函數應該在方法屬性中。 –

+0

@SrinivasDamam對不起,錯字,它是一種方法支柱。其他模型正在分配值,但不是inventoryCode。 –

+0

你在'components:{Typeahead}'中有一個大寫「T」。它不應該是小寫嗎? – redshift

回答

0
inventoryCallBack: function(item){ 
        console.log(item.inventory_code); 
        this.inventoryCode = item.inventory_code; 
        this.inventoryName = item.inventory_name; 
        this.inventoryId = item.id; 
        return item.inventory_code 
       }, 

這應該做的伎倆,錯過了這部分內容。