我如何在onEnter函数中执行异步?,我的情况如下:
我的行动:
export function getSetupTabTitles(category){
return function(dispatch){
axios.get(`${ROOT_URL}/api/component/getSetupTabTitles/${category}`,
{
headers:{authorization:`Bearer `+localStorage.getItem('laravel_user_token')}
}).then(response => {
dispatch({type: GET_SETUP_TAB_TITLES,
payload: response.data.setupTabTitles
});
});
}
}
我的第二个动作:
export function getPeriod(){
return function(dispatch){
axios.get(`${ROOT_URL}/api/setup/getPeriod`,
{
headers:{authorization:`Bearer `+localStorage.getItem('laravel_user_token')}
}
).then(response => {
dispatch({type: GET_PERIOD,
payload: response.data.activePeriod
});
});
}
}
我在OnEnter中的功能
import { store } from '../store/store';
import { getSetupTabTitles } from '../actions/comp.action';
import { getPeriod } from '../actions/setup.action';
export function GET_SetupTabTitles() {
store.dispatch(getSetupTabTitles('Setup'));
store.dispatch(getPeriod());
}
我需要按顺序调度它们以在转换之前获取数据。