Can someone please assist me with this issue that has been causing me trouble for days?
I am working on updating the quantity and total price in a checkout card:
The parent component:
<template>
<div>
<upsell-checkout-product
:product="product"
:index="index"
@remote="remove"
@increment="increment"
@decrement="decrement"
></upsell-checkout-product>
</div>
</template>
<script>
export default {
props: {
runId: {
type: String,
default: null
},
card: {
type: Array,
default: null
},
customer: {
type: Object,
default: null
},
order: {
type: Object,
default: null
}
},
data() {
return {
localCard: []
}
},
mounted() {
this.localCard = this.card;
},
methods: {
increment(index) {
Vue.set(this.localCard[index], 'quantity', this.localCard[index].quantity+=1);
},
decrement(index) {
if(this.localCard[index].quantity > 0) {
this.localCard[index].quantity--;
}
},
remove(index) {
this.localCard.splice(index, 1);
}
}
}
</script>
Child component:
<template>
<div class="text-green">
<div class="flex center p-2">
<div class="w-1/3">
<img class="rounded-full h-24 w-24 border border-green"
:src="'/storage/articles/' + product.article.image_url"
v-if="product.article.image_url"
/>
</div>
<div class="w-2/3">
<h3>{{ product.article.name }}</h3>
<h5 class="mt-2">Bestaalstatus</h5>
<div>
<div class="bg-red text-white text-xs mt-2 rounded p-1 w-1/3">
Niet voldaan
</div>
</div>
</div>
</div>
<div class="center justify-between p-2 border-t border-b border-dotted border-green">
<div class="w-1/5">
<div class="cursor-pointer" @click="$emit('remove', index)">
x
</div>
</div>
<div class="center w-2/5">
<div class="cursor-pointer" @click="$emit('decrement', index)">
-
</div>
<input type="number"
class="input-main w-1/2 ml-1 mr-1 h-8"
v-model="product.quantity">
<div class="cursor-pointer" @click="$emit('increment', index)">
+
</div>
</div>
<div class="flex justify-end w-2/5">
<div v-if="product.article.member_discount_percentage">
<p class="text-sm">€ <strike>{{ price }}</strike> - € {{ discountPrice }}</p>
</div>
<div v-else>
<p class="text-sm">€ {{ discountPrice }}</p>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: ['product', 'index'],
computed: {
price: function() {
return (this.product.quantity * this.product.article.price).toFixed(2);
},
discountPrice: function() {
return (this.product.quantity * this.product.article.discount_price).toFixed(2);
}
}
}
</script>
I have encountered an issue where card items that have not been fetched from the server but added during the checkout process are not reactive within the localCard...
Although I attempted to create a JsFiddle, I was unable to replicate the problem. It appears to be related to reactivity, and I am unsure of how to resolve it.
https://i.stack.imgur.com/1J4p3.png
Your assistance would be greatly appreciated. Thank you!