文章目录
- 1. 公共方法
- 2. 使用
1. 公共方法
methods: {// 数字换算graceNumber(number) {if (number == 0) {return "0";} else if (number > 999 && number <= 9999) {return (number / 1000).toFixed(1) + 'k';} else if (number > 9999 && number <= 99999) {return (number / 10000).toFixed(1) + 'w';} else if (number > 99999) {return "10w+";}return number;},
}
2. 使用
页面
<template><view @click="openMask()"style="margin-left: 50rpx;display: flex;flex-direction: column;justify-content: center;"><textstyle="color: #ffffff;font-size: 14px;font-weight: bold;align-self: center;">{{getGraceNumber(pageUserInfo.totalLikeMeCounts)}}</text><text style="color: #ffffff;font-size: 12px;font-weight: 300;align-self: center;">获赞</text></view>
</template>
方法区
methods: {// 把超过1000或10000的数字调整,比如1.3k/6.8wgetGraceNumber(num) {return getApp().graceNumber(num);},}