I have a watch to check the selected tags:
watch: {
search (val) {
for (let i = 0; i < val.length; i++) {
this.form_data.products_credit.push({
product_id: val[i].id,
quantity: null,
package_size: null,
purchase_price: null,
warehouse_id: null
});
}
}
}
This works fine but the problem when the user select for example tag1 then
this.form_data.products_credit value is equal to:
[
{
product_id: 1,
quantity: null,
package_size: null,
purchase_price: null,
warehouse_id: null
}
]
After that if the user selected tag2 then this.form_data.products_credit result will be:
[
{
product_id: 1,
quantity: null,
package_size: null,
purchase_price: null,
warehouse_id: null
},
{
product_id: 2,
quantity: null,
package_size: null,
purchase_price: null,
warehouse_id: null
},
{
product_id: 2,
quantity: null,
package_size: null,
purchase_price: null,
warehouse_id: null
}
]
What I am expecting:
I was not expecting the duplicated that happened after selecting another tag but that is normal since I am looping throw them.
What I have done:
I have tried to empty my products_credit before the loop like this:
this.form_data.products_credit = []
before the loop.
It worked fine but I don't want it that way because it will has side-effects on my next step.
A working example of the problem: here