To implement a filter in main.js:
Vue.filter('formatNumber', (value) => {
endings=['k','m','b','t']
if(n.length<4){
return n;
}else{
return `${n[0]}${n[1]!='0'?`.${n[1]}`:''}${endings[Math.floor((n.length-1)/3)-1]}`;
}
})
If the number is greater than or equal to 1000 (4 digits), the filter will display the first digit n[0]
. If the next digit is not 0, it will be included with a dot. The ending is determined by the original length.
Next, in your code:
<div v-for="item in items" :key:"item">
<span>{{item.num | formatNumber}}</span>
</div>