Is there a way to use JSON files in Vue.js to filter data based on category when a button is pressed? I have objects with categories inside the data.
portfolio-v1.json
{
"data":[
{
"image_path":"static/products/DELUXE-BATHROBE.jpg",
"title":"Beautiful Designs",
"heading":"Lorem Ipsum is simply dummy.",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"vendor":"George Courey",
"category":"Blanket"
},
{
"image_path":"static/products/HOME-CARE-SLIP-PAD.png",
"title":"Mutifunctionals Blocks",
"heading":"Lorem Ipsum is simply dummy.",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"vendor": "George Courey",
"category": "Blanket"
},
{
"image_path":"static/products/HERRINGBONE-THERMAL-BLANKET.jpg",
"title":"Vuejs App For Game",
"heading":"Lorem Ipsum is simply dummy.",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"vendor": "George Courey",
"category": "Blanket"
}
]
}
portfolioGrid.vue
<template>
<div class="row col-space">
<!-- START PORTFOLIO FILTER AREA -->
<div class="col-12">
<div class="text-center">
<div class="portfolio-filter mb-40">
<button class="active" data-filter="*">Show all</button>
<button data-filter=".cat1">Linens</button>
<button data-filter=".cat2">Blankets</button>
<button data-filter=".cat3">Protective Products</button>
<button data-filter=".cat4">Top Sheets</button>
<button data-filter=".cat5">Staff Apparel</button>
<button data-filter=".cat6">Towels</button>
<button data-filter=".cat7">Bathrobes & Slippers</button>
</div>
</div>
</div>
<!-- END PORTFOLIO FILTER AREA -->
<div v-for="(portfolio,index) of portfoliov1.data.slice(0,showNoOfPosts)" :key="index"
class="col-sm-12 col-md-6 col-lg-4 ">
<div class="overlay-wrap">
<img :src="portfolio.image_path" alt="gallery images" class="img-fluid border-rad w-100" height="500"
width="500"/>
<a :href="portfolio.image_path" class="card-img-overlay primary-tp-layer pos-center text-center"
data-fancybox="images">
<span class="center-holder">
<a class="ih-fade-down square-40 rounded-circle bg-white shadow-md">
<i class="fa fa-plus align-middle"></i>
</a>
</span>
</a>
</div>
</div>
</div>
</template>
<script>
import portfoliov1 from 'Components/data/portfolio-v1.json'
export default {
props: ['showNoOfPosts'],
data() {
return {
portfoliov1
}
}
}
</script>
I am looking for a way to dynamically display items based on the selected category using buttons. The goal is to filter out and display only items that match the selected category. Any suggestions on how this can be achieved?