mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-22 16:39:35 +08:00
添加一个讲解如何使用MobX的Demo
This commit is contained in:
38
MobXDemo1/assets/Script/Helloworld.ts
Normal file
38
MobXDemo1/assets/Script/Helloworld.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { observer, render } from "./Observer";
|
||||
import { StoreHello } from "./StoreHello";
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
@observer
|
||||
export default class Helloworld extends cc.Component {
|
||||
|
||||
@property(cc.Label)
|
||||
label: cc.Label = null;
|
||||
|
||||
@property
|
||||
text: string = 'hello';
|
||||
|
||||
__preload() {
|
||||
console.log('__preload');
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
console.log('onLoad');
|
||||
}
|
||||
|
||||
start() {
|
||||
console.log('start');
|
||||
// this.label.string = this.text;
|
||||
}
|
||||
|
||||
@render
|
||||
showCount() {
|
||||
console.log('hello', StoreHello.getInstance().count);
|
||||
this.label.string = '' + StoreHello.getInstance().count;
|
||||
}
|
||||
|
||||
onBtnAcount() {
|
||||
StoreHello.getInstance().addCount();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user