-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于mobx中的action(写法问题,必须包裹在匿名函数里(并非必须,写成箭头函数的形式)) #89
Labels
Comments
关于mobx中action的作用
|
进一步测试发现:(此处的描述不太准确,看下面的描述)
import {observable, action} from 'mobx'
import NattyFetch from 'natty-fetch'
export default class DemoStore {
// 被观察的属性
@observable content = ''
// 同步action示例
@action clearContent() {
this.content = ''
}
test(){
console.log('123');
//this.content = 'test again';
}
}
....
//组件中
const stroeTest = new DemoStore();
...
<div>
<div>test测试:</div>
<Button onClick={stroeTest.test}>test</Button>
<div>{stroeTest.content}
</div>
</div> |
有 export default class DemoStore {
// 被观察的属性
@observable content = ''
@action test(){
console.log('123');
this.content = 'test again';
console.log('content:'+this.content);
}
}
/******************************************************/
const store3 = new DemoStore();
...
<div>
<div>test3测试:</div>
<Button onClick={store3.test.bind(this)}>test</Button>
<div style={{marginBottom:'100px'}}>{store3.content}</div>
</div> 测试:
|
最新的测试发现,如果@action包裹的函数写成箭头函数的形式,则组件中的调用可以不需要再外边包裹一层匿名函数 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在测试一个简单的Counter时遇到的问题
The text was updated successfully, but these errors were encountered: