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 v-for="(flatno,index) in Flats "
:key="index" v-show="flatno.status ==='sold'" >
{{flatno.status.length}}
</span>
CodePudding user response:
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 >
{{flatSoldStatusLength}}
</span>