I have a method that generates an array of objects in the following way:
onCalculate_a(code)
{
let data = this.forms.calculate_a.map((p,i) => {
return {
product_code: code,
price: p
}
});
this.supplier_a = data;
},
I've attached this method to the input event:
<input type="number" @input="onCalculate_a(material.product_code)" v-model="forms.nprice_a[index]">
The issue is that the function gets executed with every input, causing the product_code to always be replaced by the value of the last input.
Desired output:
{ product_code: BB, price: 100 },
{ product_code: CC, price: 200 }
Actual output:
{ product_code: CC, price: 100 },
{ product_code: CC, price: 200 }
Is there another approach I can take to prevent the product_code from being overridden by the last input?
Here's my jsfiddle: https://jsfiddle.net/damakuro221/y2Lfrsvd/11/