Skip to content

Commit 9cc0b1f

Browse files
committed
fix: 修复Number(0)场景
1 parent fc17b58 commit 9cc0b1f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

components/_util/utils.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export const extractPropsDefaultValue = (props: { [key: string]: any }) => {
7272

7373
// 10px => 10
7474
export const depx = (value: string | number): number => {
75+
if (isUndefined(value) || isNull(value)) {
76+
return undefined;
77+
}
7578
if (isString(value) && value.endsWith('px')) {
7679
const formatValue = value.slice(0, value.length - 2);
7780
if (isFinite(Number(formatValue))) {
@@ -81,26 +84,21 @@ export const depx = (value: string | number): number => {
8184
if (isFinite(Number(value))) {
8285
return Number(value);
8386
}
84-
8587
console.warn('[depx] 转换失败,原始值为:', value);
86-
if (isUndefined(value) || isNull(value)) {
87-
return undefined;
88-
}
8988
return value as number;
9089
};
9190

9291
// 10 => 10px
9392
export const pxfy = (value: string | number): string => {
93+
if (isUndefined(value) || isNull(value)) {
94+
return undefined;
95+
}
9496
if (isFinite(value)) {
9597
return `${value}px`;
9698
}
9799
if (isFinite(Number(value))) {
98100
return `${Number(value)}px`;
99101
}
100-
101-
if (isUndefined(value) || isNull(value)) {
102-
return undefined;
103-
}
104102
return value as string;
105103
};
106104

0 commit comments

Comments
 (0)