mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-08 06:38:37 +08:00
添加一个讲解如何使用MobX的Demo
This commit is contained in:
21
MobXDemo1/assets/Script/StoreHello.ts
Normal file
21
MobXDemo1/assets/Script/StoreHello.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { observable, action } from "mobx";
|
||||
|
||||
export class StoreHello {
|
||||
|
||||
private static instance: StoreHello = null;
|
||||
public static getInstance() {
|
||||
if (this.instance == null) {
|
||||
this.instance = new StoreHello();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
@observable
|
||||
public count: number = 0;
|
||||
|
||||
@action
|
||||
public addCount() {
|
||||
this.count = this.count || 0;
|
||||
this.count++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user