-1
console.log("+++++++++++++++++++++++++", document.getElementById("liqcont").attributes);
一个.tsx文件的return{}
部分之前。
打字稿返回错误
TS2531:对象可能是空。
我需要liqcont div的样式属性来查看哪些类属性已被实际渲染。任何其他方式来做到这一点?
console.log("+++++++++++++++++++++++++", document.getElementById("liqcont").attributes);
一个.tsx文件的return{}
部分之前。
打字稿返回错误
TS2531:对象可能是空。
我需要liqcont div的样式属性来查看哪些类属性已被实际渲染。任何其他方式来做到这一点?
您可以尝试使用refs,然后在componentDidMount中使用ref获取该元素的所有属性。像这样的东西应该工作:
class Test extends React.Component {
componentDidMount(){
let attributes = this.refs["wrapper"].attributes;
}
render(){
return (
<div ref="wrapper">
........
</div>
)
}
}
React.render(<Test />, document.getElementById('container'));
希望这有助于。
错误消息 - “'ReactInstance'@boky类型中不存在'TS2339:属性'属性'' – newCoderNoCoder
反应只是一个坏主意:D – ixpl0
您是否尝试过参考? – Boky
我还没有尝试与裁判。你能告诉我该怎么做吗? – newCoderNoCoder