我正在Stackoverflow和Github上搜索和搜索解决方案,但是1.5天是不够的 - 我没有看到我犯错的地方。我有我的组件的代码,我想从两个端点获取数据,并在存储更新后我控制台记录一些东西。
class ExampleComponent extends Component {
componentDidMount(){
this.fetchData()
}
fetchData(){
const {dispatch} = this.props
Promise.all([
dispatch(getTodos()),
dispatch(getPhotos())
])
.then(() => {
console.log('I did everything!');
});
}
render() {
return (
<h1>Something</h1>
);
}
}
export default connect()(ExampleComponent)
这是我的行动......
export function getPhotos() {
return function(dispatch) {
axios.get('https://jsonplaceholder.typicode.com/photos')
.then((response) => {
console.log('photos')
dispatch({type: 'PHOTOS_REQUEST_SUCCESS',payload: response})
})
.catch((err) => {
dispatch(photosRequestError(err))
})
}
}
export function getTodos() {
return function(dispatch){
axios.get('https://jsonplaceholder.typicode.com/todos')
.then(
(response) => {
console.log('todos')
dispatch({type: 'TODOS_REQUEST_SUCCESS', payload: response})
})
.catch((err) => {
dispatch(todosRequestError(err))
})
}
}
在控制台中我得到“我做了一切”,“待办事项”,“照片”。我应该如何修改我的代码以先更新商店,然后在控制台中记录“我做了所有事情”?
提前致谢
答案 0 :(得分:1)
您需要自己返回承诺,以便链接应用同步,因此请尝试在两个函数中将public void RefreshFigure(Level lev)
{
gameObject.SetActive(true);
_collider.enabled = true;
if(_type != FigType.Death && _type != FigType.Transparent)
_collider.isTrigger = false;
ResetTransform();
if (_type == FigType.Normal)
{
lev.hasNormal = true;
lev.normalQTY++;
Debug.Log("Current Level has Normal: " + lev.hasNormal);
Debug.Log("Current Level Normal QTY issssss: " + lev.normalQTY);
}
添加到return
。