【发布时间】:2020-01-12 23:14:45
【问题描述】:
我有使用 vuejs2 的项目 这是html代码
<input @keyup='check_item_offer(arrayresult.id, arrayresult.unit_id, arrayresult.qty, key, 16)' v-model='arrayresult.qty' />
这是 vuejs2 方法中的 check_item_offer 代码
check_item_offer:function(item_id ,unit_id, quantity, key, tax) {
this.taxss = tax;
$.ajax({
type:'POST',
url: path + 'check_item_offer',
data: {
item_id: item_id,
unit_id: unit_id,
quantity: quantity
},
success:(data) => {
console.log(data);
if(data != '') {
$.ajax({
type:'POST',
url: path + 'get_item_data',
data: {
item_id: item_id,
unit_id: unit_id
},
success:(datas) => {
data['item_sale_offer_detale_price'] = data['item_sale_offer_detale_price'] * (1 + this.taxss / 100);
datas = datas * (1 + this.taxss / 100);
var qty = this.arrayresults[key].qty;
var old_price = datas;
var offer_quantity = data['item_sale_offer_detale_quantity'];
var remain = this.arrayresults[key].qty % data['item_sale_offer_detale_quantity'];
var new_price = data['item_sale_offer_detale_price'];
var item_with_new_price_quantity = qty - remain;
var price_with_offers = (item_with_new_price_quantity / offer_quantity) * new_price;
var price_without_offers = old_price * remain;
var total_price = (price_with_offers + price_without_offers) / qty;
this.arrayresults[key].item_smallest_unit_selling_price = total_price;
this.arrayresults[key].items_quantity_selling_price = total_price;
}
});
}
}
});
}
一切正常
如果我使用 keyup 更改 arrayresult.qty 它将正常工作
但是如果我使用 ajax 调用任何其他方式更改arrayresult.qty keyup 它不会运行check_item_offer,直到我进入输入并按任意键
即使我更改了 arrayresult.qty 甚至 ajax 调用,我如何运行 check_item_offer?
谢谢
【问题讨论】:
-
注释
this.taxss = tax;之后的所有代码并再次检查?还要检查 console.log(item_id,unit_id,quantity,key,tax) 中item_id,unit_id,quantity,key,tax的值并共享? -
变化发生在 this.taxss = tax;在ajax调用中
-
aah..
thisreference...this里面ajax成功回调的通病和你想象的完全不一样。
标签: vue.js vuejs2 vue-router