我想在渲染后獲取 Rect 中元素的行高,為此我使用 useRef
const titleLineHeight = titletext.current?.style.lineHeight;
我沒有得到任何價值 CSSStyleDeclaration

我不確定如何獲得這些值。請幫我
提前致謝 :)
uj5u.com熱心網友回復:
使用 getComputedStyle()
https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
const paraRef = useRef(null);
useEffect(() => {
const paraStyle = paraRef.current && getComputedStyle(paraRef.current);
console.log(paraStyle.lineHeight);
}, []);
return (
<div className="App">
<p ref={paraRef}>New text</p>
</div>
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/344934.html
