繁体   English   中英

如何在 CountUp JS package 中添加逗号

[英]How to add commas to CountUp JS package

我在 React 中为 JS 使用CountUp package。 你可以在这里找到它。 问题是当一个数字大于 1000 时,它不会像这样显示: 1,000这将是我的理想解决方案。

这是我目前拥有的代码

$<CountUp decimal="," end={todaysStats.money_earned} duration={3} />

如您所见,我尝试添加decimal=","但它不起作用。

在这种情况下,我正在计算货币,但它应该适用于大于 1000 的任何其他数字。

我该如何处理这个问题?

根据文档,您需要使用separator而不是小数

separator: string 指定千位分隔符的字符。

https://github.com/glennreyes/react-countup#separator-string

<CountUp start={animate ? 100.000 : null} end={200.000} duration={1} separator=" " decimals={3}
                decimal="," redraw={true}>
            {({ countUpRef }) => (
              <div>
                <span ref={countUpRef} className="number" />
                <VisibilitySensor
                  onChange={isVisible => {
                    if (isVisible) {
                      setAnimate(true);
                    } 
                  }}
                >
                  <span className="subtext" > members</span>
                </VisibilitySensor>
              </div>
            )}
          </CountUp>

解决方案:

  • <CountUp separator=',' delay={2} end={7000} />

https://www.npmjs.com/package/react-countup

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM