我试图在我的React应用程序中实现Alt。 目前我正在检查它,并试着按照教程做一些事情。现在我遇到了商店无法识别操作的问题。Alt + React - 以下alt教程无效的操作参考
这是操作类:
import alt from '../libs/alt';
import WishSource from '../sources/WishSource';
class WishActions {
fetchWishes() {
this.dispatch();
WishSource.fetch()
.then((wishes) => {
this.actions.fetchWishesSuccess(wishes);
})
.catch((err) => {
this.actions.fetchWishesFailed(err);
});
}
fetchWishesSuccess(wishes) {
this.dispatch(wishes);
}
fetchWishesFailed(err) {
this.dispatch(err);
}
}
export default alt.generateActions(WishActions);
我尝试如下绑定在我的商店这些操作:
import alt from '../libs/alt';
import WishActions from '../actions/WishActions';
class WishStore {
constructor() {
this.wishes = [];
this.errorMessage = null;
this.bindListeners({
handleFetchWishes: WishActions.FETCH_WISHES,
handleFetchWishesSuccess: WishActions.FETCH_WISHES_SUCCESS,
handleFetchWishesFailed: WishActions.FETCH_WISHES_FAILED
});
}
handleFetchWishesSuccess(wishes) {
this.wishes = wishes;
this.errorMessage = null;
}
handleFetchWishes() {
this.wishes = [];
}
handleFetchWishesFailed(err) {
this.errorMessage = err;
}
}
export default alt.createStore(WishStore, 'WishStore');
我一直给我的错误
“无效'
问题出在bindListeners函数的某个地方。
如果我尝试bindActions它说:
'_WishActions2.default.fetchWishes不是一个函数'
,这是在视图中。这里我打电话WishActions.fetchWishes()
componentDidMount()
我无法理解这里发生了什么问题。 如果我看教程和其他例子,这应该工作。
有人可以帮助我在这里,也许解释什么是错的?