MobX 核心 API :
定义状态(observable)
响应状态(autorun, computed)
修改状态(action)
import { observable, autorun, computed, action } from 'mobx';// 1. 定义状态const store = observable({ count: 0,});// 2. 响应状态// 计算值const count10 = computed(() => { return 10 * store.count;});// 定义响应函数autorun(() => { console.log('count:', store.count, count10.get());});// 3. 修改状态// 方式一:直接修改状态store.count += 1;store.count += 1;store.count += 1;// 方式二:显式修改状态const increase = action(() => store.count++);increase();