Skip to content

Commit 8979694

Browse files
committed
feat: 调整useViewControl逻辑
1 parent 2317fa9 commit 8979694

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/src/hooks/useViewControl.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@ export function useViewControl({ props, cminstance, presetRef }: UseViewControlP
2424
});
2525
};
2626

27+
const isStringNumber = (value?: string | number | null) => {
28+
return value && isNaN(+value) ? false : true;
29+
};
30+
2731
const resize = (width = props.width, height = props.height) => {
2832
let cmWidth = "100%";
2933
let cmHeight = "100%";
30-
console.log("resize", width, width);
3134

32-
if (typeof width === "number") {
35+
if (isStringNumber(width)) {
3336
cmWidth = `${String(width)}px`;
3437
} else if (width) {
35-
cmWidth = width;
38+
cmWidth = width as string;
3639
}
3740

38-
if (typeof height === "number") {
41+
if (isStringNumber(height)) {
3942
cmHeight = `${String(height)}px`;
4043
} else if (height) {
41-
cmHeight = height;
44+
cmHeight = height as string;
4245
}
4346

4447
containerWidth.value = cmWidth;

0 commit comments

Comments
 (0)