Skip to content

Commit 4e9f2fd

Browse files
committed
feat(price): 价格净化
1 parent a9e16bc commit 4e9f2fd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/packages/price/price.taro.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const defaultProps = {
2020
export const Price: FunctionComponent<Partial<TaroPriceProps>> = (props) => {
2121
const {
2222
color,
23-
price,
23+
price: originalPrice,
2424
symbol,
2525
digits,
2626
thousands,
@@ -38,6 +38,10 @@ export const Price: FunctionComponent<Partial<TaroPriceProps>> = (props) => {
3838

3939
const rtl = useRtl()
4040

41+
const price = useMemo(() => {
42+
return originalPrice.toString().replace(/[^\d.]/g, '')
43+
}, [originalPrice])
44+
4145
const isCustomPriceColor = useMemo(() => {
4246
const specificPriceColor = Object.values(PriceColorEnum)
4347
return !specificPriceColor.includes(color as PriceColorEnum)

src/packages/price/price.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const defaultProps = {
1818
export const Price: FunctionComponent<Partial<WebPriceProps>> = (props) => {
1919
const {
2020
color,
21-
price,
21+
price: originalPrice,
2222
symbol,
2323
digits,
2424
thousands,
@@ -37,6 +37,10 @@ export const Price: FunctionComponent<Partial<WebPriceProps>> = (props) => {
3737

3838
const rtl = useRtl()
3939

40+
const price = useMemo(() => {
41+
return originalPrice.toString().replace(/[^\d.]/g, '')
42+
}, [originalPrice])
43+
4044
const isCustomPriceColor = useMemo(() => {
4145
const specificPriceColor = Object.values(PriceColorEnum)
4246
return !specificPriceColor.includes(color as PriceColorEnum)

0 commit comments

Comments
 (0)