下面是我的代码:
export default class CouseTest extends Component{ static defaultProps = { x:1, y:'4' } constructor(props){ super(props); this.state={ x:0 } } onClicks(){ let imgX = this.props.x;//props let imgTarget = document.getElementsByTagName('img'); let boxTarget = document.getElementsByClassName('moveBox')[0]; let imgWidth = imgTarget[0].offsetWidth; let imgLength = imgTarget.length; boxTarget.style.marginLeft = -(this.state.x)+'px';//state } render(){ })
在点击事件里面获取 state
和 props
的值时,结果都为空,这个地方要怎么弄呢,求指教
相关分类