You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

23 lines
526 B

// 初始化 mobx
import { makeAutoObservable } from 'mobx'
class CounterStore {
// 1.定义数据
count = 0
// constructor() 是构造函数 作用:1.初始化this.state 2.函数方法绑定到实例。
constructor() {
// 2. 将数据弄成响应式
makeAutoObservable(this)
}
// 3.定义 action 函数 (修改数据)
addCount = () => {
this.count++
}
}
// 4.实例化,然后导出给 react 使用
const counterStore = new CounterStore()
export {counterStore}