当前位置:网站首页>If the uniapp is less than 1000, it will be displayed according to the original number. If the number exceeds 1000, it will be converted into 10w+ 1.3k+ display

If the uniapp is less than 1000, it will be displayed according to the original number. If the number exceeds 1000, it will be converted into 10w+ 1.3k+ display

2022-07-04 10:06:00 gblfy

 Insert picture description here

List of articles

1. Public methods
methods: {
    
			//  Number conversion 
			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. Use

page

<template>
			<view @click="openMask()"
						style="margin-left: 50rpx;display: flex;flex-direction: column;justify-content: center;">
						<text
							style="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;"> Be praised </text>
					</view>
</template>

Method area

	methods: {
    
			//  Put more than 1000 or 10000 Digital adjustment of , such as 1.3k/6.8w
			getGraceNumber(num) {
    
				return getApp().graceNumber(num);
			},
	}
原网站

版权声明
本文为[gblfy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040936285928.html