課程
/前端開(kāi)發(fā)
/React.JS
/基于實(shí)例的 React16 傻瓜課程
照著老師一模一樣寫(xiě)的
怎么我的時(shí)間不變化,定時(shí)器沒(méi)作用
2018-10-09
源自:基于實(shí)例的 React16 傻瓜課程 3-3
正在回答
拼寫(xiě)錯(cuò)誤 componentDidMont 應(yīng)該是 componentDidMount, 下次注意歐
qq_嶸歸_0 提問(wèn)者
張軒 回復(fù) qq_嶸歸_0 提問(wèn)者
qq_嶸歸_0 提問(wèn)者 回復(fù) 張軒
代碼貼來(lái)看看
import React, { Component } from 'react';import Clock from './Clock';class App extends Component {render() {return (<div><Clock /></div>);}}export default App;
import React from 'react';
class Clock extends React.Component{
constructor(props){
super(props);
this.state={
date:new Date()
}
componentDidMont(){
this.timer=setInterval( ()=>{
this.setState({
date: new Date()
})
}, 1000)
componentDidUpdate(currentProps,currentState){
console.log(currentState)
componentWillUnmount(){
clearInterval(this.timer)
render(){
return(
<h1>{this.state.date.toLocaleTimeString()}</h1>
)
?}
?export default Clock;
張軒
hao
舉報(bào)
通過(guò)一系列簡(jiǎn)單有趣的例子,讓你了解 React16 的基本概念和新特性
2 回答console的12能定時(shí)打印,就是時(shí)間不變,為什么呢
1 回答問(wèn)視頻時(shí)間
1 回答我看其它視頻時(shí),沒(méi)有安裝create-react-app這一步操作
2 回答什么時(shí)候用受控組件,什么時(shí)候用非受控組件?
2 回答為什么使用state的時(shí)候必須使用constructor的方式
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-10-10
拼寫(xiě)錯(cuò)誤 componentDidMont 應(yīng)該是 componentDidMount, 下次注意歐
2018-10-09
代碼貼來(lái)看看
2018-10-09
import React, { Component } from 'react';
import Clock from './Clock';
class App extends Component {
render() {
return (
<div>
<Clock />
</div>
);
}
}
export default App;
2018-10-09
import React from 'react';
class Clock extends React.Component{
constructor(props){
super(props);
this.state={
date:new Date()
}
}
componentDidMont(){
this.timer=setInterval( ()=>{
this.setState({
date: new Date()
})
}, 1000)
}
componentDidUpdate(currentProps,currentState){
console.log(currentState)
}
componentWillUnmount(){
clearInterval(this.timer)
}
render(){
return(
<h1>{this.state.date.toLocaleTimeString()}</h1>
)
}
?}
?export default Clock;
2018-10-09
hao