我想立即向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