[Vuejs]-Is it possible to subtract the number of a particular class from the page count?

0👍

I’d do it like this, assuming that items that have a deletedAt that is not null or undefined are supposed to be hidden. It’s generally easier to work from a data perspective, rather than setting the CSS class first and then trying to get data information from which CSS class is set again:

computed: {
  visibleResultsCount() {
    const hiddenItems = this.result.filter(x => x.deletedAt != undefined)  // this callback function is assumed for my case, and should be the same as the one you use to check if you should hide with CSS.
    return Object.keys(this.result).length - Object.keys(hiddenItems).length;
}

Of course you could also filter on visible items instead and get the length from that. The main takeaway is to compute with the data itself rather than trying to count elements with a CSS class.

Leave a comment