当前如下:
import React from 'react';
class Index extends React.Component {
constructor(props) {
this.ref= React.createRef();
}
componentDidMount = () => {
// 都无效,undefined
console.log(this.ref.getBoundingClientRect);
console.log(this.ref.current.clientHeight);
}
render() {
return (
...
<div ref={this.ref}></div>
...
)
}
}
getBoundingClientRect 不用加()吗?