I am passing in products
as a prop to this component. I am then setting a data value to those props because I am going to be pushing products to it.
In my template, I am using a computed property productsToShow
because if a prop hideSoldOutProducts
is passed in, they get filtered out.
My question is: I made productsData
a data value because at the bottom of the page, their will be an API call to push more products to the productsData
array. So although the productsData
is being added to, the computed property productsToShow()
which is using the productsData
is not reflecting this.
<template>
<div v-for="(product, index) in productsToShow">
.....
</div>
</template>
data() {
return {
productsData: Vue.util.extend([], this.products.data)
}
},
props: {
products: {type: Object},
hideSoldOutProducts: {type: Boolean}
},
computed: {
productsToShow() {
if (!this.products.data) {
return []
}
if (this.hideSoldOutProducts) {
let filteredList = this.productsData.filter(x => x.product.inventory_quantity.quantity > 1)
return filteredList
} else {
return this.productsData
}
}
}
productsData
? – Steven B.this.productsData = response.data.data
in the success part of the API call so I can seethis.productsData
having more data added to it in the Vue devtools – herkypam