Hey there, I'm currently working with Laravel ORM and Vue 2.
I've encountered some issues with analyzing Json data.
Here's my Laravel ORM code:
$banner = Banner::with('banner_img')->get();
return response()->json($banner);
This is the Json data I am dealing with:
[{"id":10,"banner":"AIR","banner_img":[{"id":1,"img":"air_1.png","banner_id":10},{"id":2,"img":"air_2.png","banner_id":10}]},
{"id":11,"banner":"HOT","banner_img":[{"id":3,"img":"hot_1.png","banner_id":11},{"id":4,"img":"hot_2.png","banner_id":11}]},
{"id":12,"banner":"NEW","banner_img":[{"id":5,"img":"new_1.png","banner_id":12},{"id":6,"img":"new_2.png","banner_id":12}]}]
My json data contains two arrays.
I need to filter this json data (banner_img:['img']) using Vue.js.
For Vue.js, here's what I have:
var app = new Vue({
el: '#app',
data: {
banner:[],
search:'',
},
methods: {
getBannerData: function() {
axios.get('/case/ajax/33').then(response => {
this.banner = response.data.banner;
});
},
},
mounted: function() {
this.getBannerData();
},
computed: {
filteredList() {
return this.banner(value => {
return value.banner.banner_img.img.toLowerCase().includes(this.search.toLowerCase())
})
}
}
});
As for the HTML part:
<input type="text" name="ImgFilter" v-model="search">
<div v-for="value in filteredList">
<img v-for="imgs in value.banner_img" :src="imgs.img" height="100">
</div>
I tried
return value.banner.banner_img.img
, but that didn't work as expected.
Any advice or suggestion would be greatly appreciated. Thanks in advance!