滑动输入条页面刷新时只会读取第一次传入的属性值,在没有用传入id获取到正确的默认值时,页面已经被渲染了。this
使用默认选中属性defaultChecked 缺点: 只会在页面第一次请求数据的时候按条件渲染spa
最后解决办法:code
按需求来使用属性,若是你须要的只是默认为一个状况,所有false或者true,这个时候用defaultChecked便可blog
若是界面带有数据,有默认的值须要渲染的话,建议使用checkedget
状态部分:it
constructor(props) { super(props) this.state = { curIstop: false, switchIsChange: "" } }
方法部分:class
handleIsTop = (e, type) => { this.setState({ curIstop: e, switchIsChange: true }) }
render部分:渲染
<Switch
onChange={(e) => this.handleIsTop(e)} checked={this.state.switchIsChange ? this.state.curIstop : !!getNotice.istop}/>