对于React v <= 15
console.log( ReactDOM.findDOMNode(this.refs.container).style); //React v > 0.14console.log( React.findDOMNode(this.refs.container).style);//React v <= 0.13.3
编辑:
console.log(window.getComputedStyle(ReactDOM.findDOMNode(this.refs.container)).getPropertyValue("border-radius"));// border-radius can be replaced with any other style attributes;
对于React v> = 16
使用回调样式或使用createRef()分配引用。
assignRef = element => { this.container = element;}getStyle = () => { const styles = this.container.style; console.log(styles); // for getting computed styles const computed = window.getComputedStyle(this.container).getPropertyValue("border-radius"));// border-radius can be replaced with any other style attributes; console.log(computed);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)