代碼: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
);實(shí)際上并沒有使用action修飾可以更新到數(shù)據(jù),使用action修飾:let appState = observable({ time: 11, do: action(function () {
appState.time = 12;
})
})action才相當(dāng)于setState,為什么沒有啟用action仍然更新
使用mobx更新數(shù)據(jù)問題
人到中年有點(diǎn)甜
2019-03-02 19:42:12