0
這是代碼:Mobx調用操作上計算財產
@computed
get user() {
if(!this.hasValidated)
this.reloadUserData();
return this.userData;
}
@action
reloadUserData() {
return new Promise(function(ok, err) {
if(!window.localStorage['atoken'])
err({id:24, detail:'User havn\'t logged in.'});
if(!window.localStorage['aprofile'])
apicall.get('user/detail').then((data)=>{
this.setProfile(data.data.content);
ok(true);
}).catch((derr)=>{
err({id:20, detail:derr});
});
else{
this.userData=JSON.parse(window.localStorage['aprofile']);
}
}.bind(this));
}
左右,主要目標是,當配置文件數據尚未經過驗證,我們會從服務器重新獲取它,然後,而等待數據發生變化,我們將爲他們提供localstorage中的緩存值。
Anddd ....我的問題是,爲什麼它給我一個'計算值不能調用動作功能'的東西?
謝謝! :D
我認爲[lazyObservable](https://github.com/mobxjs/mobx-utils#lazyobservable)最合適。但是當它改變另一個可觀察的時候,它會觸發其他組件的更新嗎? – Chris