我发现了有关此主题的问题,但答案不起作用。我需要您的帮助才能理解。我尝试使用axios从服务器获取数据。我的错误在哪里?
export default (state = initialState, action) => {
switch (action.type) {
case GET_DATA_CUSTOMERS:
return {
...state,
data: action.data
}
default:
return state
}
}
export function getCustomersData() {
const url = 'someUrl'
return (dispatch) => {
axios.get(url)
.then(res => dispatch({
type: GET_DATA_CUSTOMERS,
data: res.data
}))
.catch(res => dispatch({
type: GET_CUSTOMER_ERROR,
error: res.error
}))
}
}