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.

22 lines
526 B

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