'我试图在刷新浏览器时遵循执行过程,但我发现saga不执行fetchOrders函数。
你有个主意吗?'
反应成分:
componentWillMount(){
this.props.dispatch({type:'FETCH_ORDERS'})
}
动作文件:
export function* fetchOrders(){
try {
let orders = JSON.parse(localStorage.getItem('orders')) || [];
yield put({type: 'FETCH_ORDERS_SUCCESS', payload: orders})
} catch (error) {
yield put({type: 'FETCH_ORDERS_ERROR', payload: error})
}
}
export default function* ordersSaga() {
yield all([
takeEvery('EDIT_ORDER', editOrder),
takeEvery('ADD_ORDER', addOrder),
takeEvery('FETCH_ORDERS',fetchOrders)
])
}