@orca-fe/pocket
Version:
UI components by orca-team
35 lines (30 loc) • 654 B
JavaScript
import { CommonStore } from "../..";
// 定义计数器的状态
// 为计数器组件 声明一个 Store (组件外置状态)
export default class CounterStore extends CommonStore {
constructor() {
// 状态默认值,你也可在构造函中增加参数,由外部传入默认值
super({
count: 0
});
}
// 取值
getValue() {
return this.state.count;
}
// 编写需要对外暴露的方法
// +1
add() {
var count = this.state.count;
this.setState({
count: count + 1
});
}
// -1
minus() {
var count = this.state.count;
this.setState({
count: count - 1
});
}
}