我想立即向DB提出請求。問題是:我無法清除以前的ajax請求的結果,即使我清除包含它的數組時,當我輸入更快時也不起作用。Vuejs無法清除之前ajax的結果
第二個(較小的:D)問題是我必須使嵌套循環,使其工作。
我想很多時間來解決這些問題......
組件1:HTML
<input v-model="invoice_number" type="text" name="invoice_number" class="form-control" id="" placeholder="Invoice number" @keyup="max_invoice_number" required>
組件1:JavaScript的
max_invoice_number: function() {
axios.get('/max_invoice_number/' + this.invoice_number)
.then(response => this.max_invoice_response.push({
info: response.data
}));
Event.$emit('max_invoice_response', this.max_invoice_response);
},
組件2 HTML
<div v-for="a in max_invoice_response" class="bg-success col-xs-12">
<div v-for="b in a">{{b.info}}</div>
</div>
元器件2的Javascript
data(){
return{
ref_numbers: [],
max_invoice_response: []
}
},
created: function(){
Event.$on('max_invoice_response', function(response) { this.clear; this.max_invoice_response.push(response); }.bind(this));
},
methods: {
clear: function() {
this.max_invoice_response.splice(0);
}
},
}
難道你不會在你創建的方法中忘記'this.clear'上的圓括號嗎? (應該是'this.clear()') –
謝謝你的回答,但它不是:) – Flash