我有一个 Mobx 商店,我在 Provider 中传递了这个商店,当我安慰this.props时,它显示了 Mobx 商店的结构。
下面是我的 Mobx 商店
import { observable, computed, action, useStrict, runInAction, toJS } from 'mobx';
// useStrict(true);
class OpenPropertiesStore {
@observable openProperties = {};
@action
fetchOpenProperties() {
fetch(`http://uinames.com/api/`)
.then(res => res.json())
.then(data => {
runInAction(() => {
this.openProperties = data;
this.name = "abhinav";
})
})
}
@computed get getOpenProperties() {
return this.openProperties;
}
}
export default new OpenPropertiesStore();
在组件内部,我正在调用 ComponentDidMount,如果我正在打印“this.props”,它会显示商店。但我不能像这样调用函数
@inject('UserStore', 'CityStore', 'OpenPropertiesStore')
@observer
export default class Navigation extends Component {
componentDidMount = async () => {
const { CityStore, UserStore, OpenPropertiesStore } = this.props;
const data = OpenPropertiesStore.getOpenProperties();
}
}
给我错误
YellowBox.js:67 可能的未处理承诺拒绝(id:0):TypeError:OpenPropertiesStore.getOpenProperties 不是函数 TypeError:OpenPropertiesStore.getOpenProperties 不是函数
任何人都知道如何解决这个错误