1👍
✅
There is not property like include in array/list it should be includes
. Small typo.
addTocart(item) {
if (this.form.items.includes(item)) { // <-- change include to includes
alert("already there");
} else {
this.form.items.push(item);
}
Vue.set(item, 'quantity', 1);
Vue.set(item, 'discount', 1);
},
Update
If res.returnpurchase
is undefined then it is setting whole form variable as undefined or if items in undefined then it is setting items as undefined which should be []
for using includes. Add check for this,
if (res.returnpurchase == undefined
|| res.returnpurchase.items == undefined) {
this.form.items = []
}
Source:stackexchange.com