0

in my Vue js project, i wanted to show the length of specific data in API and when i wrote code below i got the status sold length = 5 repeated 5 times, while i want to show only one time like 5 only is there a way to do it?

<span class="text-success mr-2" v-for="(flatno,index) in Flats " 
:key="index" v-show="flatno.status ==='sold'" >   
   {{flatno.status.length}}
</span>

1 Answer 1

2

I recommend to define a computed property called flatSoldStatusLength that returns the length of the flats with status equals to sold :

computed:{
  flatSoldStatusLength(){
    return this.Flats.filter(flat=>flat.status==='sold').length;
  }
}

in template :

<span class="text-success mr-2"  >   
   {{flatSoldStatusLength}}
</span>
Sign up to request clarification or add additional context in comments.

1 Comment

Or just {{Flats.length}} to show the length of all results. I think you've made a good guess that the OP wants to know how many meet the sold condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.