Using Vue.
I'm currently stuck at this problem, where it seems whatever data is pushed into my cart: []
is always 1 behind. I'm fairly new to javascript, and I've been spending quite a few days trying to research and try others fixes, but without any kind of luck. - I really hope someone has some input that'll help me out.
Video showing my problem: (https://youtu.be/nNRYSc4BuYo)
-- As seen in the video, my console.log('Cart Spawncode: ' + value.newSpawnCode)
is always one behind.
(this.cart
is defined earlier in my file as cart: []
)
addToCart(category, seller, spawncode, label, description, price, type) {
if (this.cart == '') {
console.log('---------------------------------')
console.log('newSpawnCode = undefined (Added)')
console.log('Cart Spawncode: ' + this.cart.newSpawnCode) // Print undefined (Good)
console.log('Spawncode: ' + spawncode)
console.log('---------------------------------')
this.cart.push({ newCategory: category, newSeller: seller, newSpawnCode: spawncode, newLabel: label, newDescription: description, newPrice: price, newType: type });
} else {
for (const [key, value] of Object.entries(this.cart)) {
if (value.newSpawnCode == spawncode) {
console.log('---------------------------------')
console.log('Exists')
console.log('Cart Spawncode: ' + value.newSpawnCode)
console.log('Spawncode: ' + spawncode)
console.log('---------------------------------')
} else {
this.cart.push({ newCategory: category, newSeller: seller, newSpawnCode: spawncode, newLabel: label, newDescription: description, newPrice: price, newType: type });
console.log('---------------------------------')
console.log('Doesent exist')
console.log('Cart Spawncode: ' + value.newSpawnCode)
console.log('Spawncode: ' + spawncode)
console.log('---------------------------------')
}
}
}
},
```