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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

Uncaught TypeError: Cannot read property 'strikes' of undefined at timerTriker (APP3.js:19)


import React from 'react';



class LightCounter extends React.Component{https://img1.sycdn.imooc.com//5ce51aea0001238816030980.jpg

constructor(props){

super(props);

this.state={

strikes:0

}

}

getInitialState(){

return {

strikes:0

}

}


timerTriker(){

this.setState({

strikes:this.state.strikes+100

})

}

componentDidMount(){

setInterval(this.timerTriker,1000)

}


render(){

return (

<div>

<h1>{this.state.strikes}</h1>

</div>

)

}

}



class LightCounterDisplay extends React.Component{

render(){

var divStyle ={

width:250,

textAlign:"center",

backgroundColor:"black",

padding:40,

color:"#999",

fontFamily:"sans-serif",

borderRadius:10

}

return (

<div style= {divStyle}>

<LightCounter />

</div>

)

}

}


export default LightCounterDisplay



正在回答

1 回答

timerTriker = () =>{

this.setState({

strikes:this.state.strikes+100

})

}

componentDidMount = () => {

setInterval(this.timerTriker,1000)

}


解決了 沒有綁定 這2個方法這樣寫 就可以了

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
React組件
  • 參與學(xué)習(xí)       26074    人
  • 解答問題       27    個

帶你了解如何創(chuàng)建好擁有各自狀態(tài)的組件,再由組件構(gòu)成更加復(fù)雜的界面

進(jìn)入課程

Uncaught TypeError: Cannot read property 'strikes' of undefined at timerTriker (APP3.js:19)

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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