第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

react 如何實(shí)現(xiàn)setInterval每過(guò)一秒在html中添加一個(gè)div ?

react 如何實(shí)現(xiàn)setInterval每過(guò)一秒在html中添加一個(gè)div ?

眼眸繁星 2019-05-22 20:54:34
react如何實(shí)現(xiàn)setInterval每過(guò)一秒在html中添加一個(gè)div?現(xiàn)在有一個(gè)需求是要每過(guò)幾秒在界面添加一個(gè)盒子之前沒(méi)寫過(guò)react函數(shù)應(yīng)該寫在componentDidMount()里面吧求大佬給個(gè)思路~現(xiàn)在實(shí)現(xiàn)了不知道怎么停下來(lái)我是真滴菜
查看完整描述

2 回答

?
縹緲止盈

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊

classAppextendsComponent{
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(){
constme=this;
this.handle=setInterval(function(){
me.setState(function(preState){
letarr=[preState.index++,...preState.arr];
return{arr};
});
if(me.state.index==me.props.max){
me.stopClickHandle();
}
},1000);
}
render(){
letarr=this.state.arr;
arr=arr.map(function(item){
return(
{item}
)
});
return(
{arr}
)
}
}
ReactDOM.render(,document.body);
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-22
?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

importReactfrom"react";
classClockextendsReact.Component{
constructor(props){
super(props);
this.state={arr:["div"]};
}
componentDidMount(){
this.timeID=setInterval(
()=>this.tick(),
1000
)
}
componentWillUnmount(){
clearInterval(this.timeID)
}
tick(){
//5個(gè)停止計(jì)時(shí)器
if(this.state.arr.length===5){
clearInterval(this.timeID);
return;
}
this.setState((prevState,props)=>({
arr:[...prevState.arr,props.add]
}))
}
render(){
return(
this.state.arr.map((item,idx)=>(

{item}

))
)
}
}
ReactDOM.render(
,
document.getElementById('root')
);
具體可以看下文檔
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-22
  • 2 回答
  • 0 關(guān)注
  • 804 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)