代码:
let appState = observable({ time: 11, do:function(){
appState.time=12
}
});const App = observer(class app extends React.Component {
componentDidUpdate(){ console.log('1')
}
render(){ return (<h2 onClick={appState.do}>Home{appState.time}</h2>;
}
})
ReactDOM.render( <App/>, document.body
);实际上并没有使用action修饰可以更新到数据,使用action修饰:
let appState = observable({ time: 11, do: action(function () {
appState.time = 12;
})
})action才相当于setState,为什么没有启用action仍然更新
人到中年有点甜
慕桂英546537
MMTTMM
随时随地看视频慕课网APP