refactor(components): [form-label-wrap] use getStyle method (#13913)

This commit is contained in:
tiansQAQ 2023-08-09 20:52:03 +08:00 committed by GitHub
parent ec639c4d14
commit c6a6d9bc6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,7 @@ import {
watch, watch,
} from 'vue' } from 'vue'
import { useResizeObserver } from '@vueuse/core' 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 { useNamespace } from '@element-plus/hooks'
import { formContextKey, formItemContextKey } from './constants' import { formContextKey, formItemContextKey } from './constants'
@ -41,8 +41,11 @@ export default defineComponent({
const getLabelWidth = () => { const getLabelWidth = () => {
if (el.value?.firstElementChild) { if (el.value?.firstElementChild) {
const width = window.getComputedStyle(el.value.firstElementChild).width const width = getStyle(
return Math.ceil(Number.parseFloat(width)) el.value.firstElementChild as HTMLElement,
'width'
)
return Math.ceil(Number.parseFloat(width)) || 0
} else { } else {
return 0 return 0
} }