Exploring the use of axios in conjunction with Vue has been my recent focus, but I find myself pondering a more general JSON inquiry.
After successfully retrieving data from my local products.json file using axios, I'm implementing filter to generate a new array containing only products that share a similar department property, and subsequently displaying them through iteration.
I wonder if this methodology is optimal, or if it's possible to somehow apply the filtering directly within the initial axios call. I've read about passing parameters to trigger specific database queries and return only the necessary JSON data initially.
data(){
return {
products: []
}
},
components: {
Product
},
computed: {
foodProducts(){
return this.products.filter(x => x.department == 'Food')
}
},
mounted() {
axios
.get('./json/products.json')
.then(response => (this.products = response.data.products))
}
Your input on this matter would be greatly appreciated as I continue delving into the underlying concepts.