尚方宝剑之说
class App extends Component{ constructor(props){ super(props); this.state={ arr:[], index:0 } this.handle=null; this.stopClickHandle=this.stopClickHandle.bind(this); } stopClickHandle(){ if(this.handle){ clearInterval(this.handle); this.handle=null; } } componentDidMount(){ const me=this; this.handle=setInterval(function(){ me.setState(function(preState){ let arr=[preState.index++,...preState.arr]; return {arr}; }); if(me.state.index == me.props.max){ me.stopClickHandle(); } },1000); } render(){ let arr=this.state.arr; arr=arr.map(function(item){ return (