From c6a6d9bc6e813ee05bb358a2e929f54d1144d9f8 Mon Sep 17 00:00:00 2001 From: tiansQAQ <46640919+tiansQAQ@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:52:03 +0800 Subject: [PATCH] refactor(components): [form-label-wrap] use getStyle method (#13913) --- packages/components/form/src/form-label-wrap.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/components/form/src/form-label-wrap.tsx b/packages/components/form/src/form-label-wrap.tsx index c2951bab88..67a2a53147 100644 --- a/packages/components/form/src/form-label-wrap.tsx +++ b/packages/components/form/src/form-label-wrap.tsx @@ -11,7 +11,7 @@ import { watch, } from 'vue' import { useResizeObserver } from '@vueuse/core' -import { throwError } from '@element-plus/utils' +import { getStyle, throwError } from '@element-plus/utils' import { useNamespace } from '@element-plus/hooks' import { formContextKey, formItemContextKey } from './constants' @@ -41,8 +41,11 @@ export default defineComponent({ const getLabelWidth = () => { if (el.value?.firstElementChild) { - const width = window.getComputedStyle(el.value.firstElementChild).width - return Math.ceil(Number.parseFloat(width)) + const width = getStyle( + el.value.firstElementChild as HTMLElement, + 'width' + ) + return Math.ceil(Number.parseFloat(width)) || 0 } else { return 0 }