Go to file
2022-09-06 23:57:26 +08:00
public feat🔫: first commit & 搭建框架,完成bill图表展示 2022-09-05 02:24:11 +08:00
src feat🔫: 添加记录入账功能 2022-09-06 23:57:26 +08:00
.gitignore feat🔫: first commit & 搭建框架,完成bill图表展示 2022-09-05 02:24:11 +08:00
default.conf.template feat🔫: docker镜像 & nginx 2022-09-06 01:05:29 +08:00
docker-compose.yaml feat🔫: docker镜像 & nginx 2022-09-06 01:05:29 +08:00
Dockerfile feat🔫: docker镜像 & nginx 2022-09-06 01:05:29 +08:00
index.html feat🔫: first commit & 搭建框架,完成bill图表展示 2022-09-05 02:24:11 +08:00
package.json fix🛠️: 统一date格式 2022-09-06 01:18:19 +08:00
README.md feat🔫: first commit & 搭建框架,完成bill图表展示 2022-09-05 02:24:11 +08:00
tsconfig.json feat🔫: first commit & 搭建框架,完成bill图表展示 2022-09-05 02:24:11 +08:00
tsconfig.node.json feat🔫: first commit & 搭建框架,完成bill图表展示 2022-09-05 02:24:11 +08:00
vite.config.ts fix🛠️: dayjs bug 2022-09-06 01:46:55 +08:00
yarn.lock fix🛠️: 统一date格式 2022-09-06 01:18:19 +08:00

.

MobX-react

yarn add mobx mobx-react-lite

  1. makeAutoObserver
export class Bill {
    bills: IBill[] = [];            // state

    constructor() {
        makeAutoObservable(this)    // makeAutoObservable
    }

    get list() {                    // 计算属性computed, 缓存结果
        return this.bills;
    }

    add(bill: IBill) {              // action修改状态
        this.bills.push(bill);
    }

    async fetch() {
        runInAction(() => {         // runInAction 异步修改状态
            this.bills.push({
                date: Date.now().toString(),
                money: 123,
                cls: "test",
                label: "test",
            })
        })
    }
}
  1. observer

observer 包裹函数式组件, 状态更新时自动刷新组件

const Home = observer(() => {...})