I have a Vue.js component that I am working with:
Vue.component('channels-list', {
data() {
return {
channels: [],
}
},
methods: {
getChannels() {
this.$http.get('/channels')
.then(response => {
this.channels = response.data;
});
}
},
ready() {
this.getChannels();
}
});
The 'channels' property is just an array of objects, for example:
[{
"id": 1,
"title": "ANB",
"image_url": "/img/1.png",
"popular": true
}, {
"id": 2,
"title": "Roya TV",
"image_url": "/img/2.png",
"popular": false
}]
Now, I am trying to add a new component property called popularChannels
, which will be used in the view to display only popular channels. I attempted to achieve this using a similar approach seen in other MVVM frameworks:
data() {
return {
channels: [],
popularChannels: function() {
return this.channels.filter(function(item) {
return item.popular
});
}
}
},
However, it doesn't seem to be working as expected.
If anybody could provide guidance on how to properly implement this functionality in Vue.js, I would greatly appreciate it. Thank you.