我正在实现React-Redux。 以下是我的操作文件中
const fetchCustomers = () => {
return (dispatch) => {
axios
.get('/api/customers')
.then((response) => {
console.log('List of all Customers - ',response)
dispatch({ type: FETCH_CUSTOMERS, payload: response.data })
})
}
};
我正在按如下方式致电行动创建者:
store.dispatch(fetchCustomers());
在响应之前的console.log int api显示正确的数据:
[0] [ { customerRequest: [ [Object] ],
[0] _id: 5c82a0444713453b9472038d,
[0] name: 'user4',
[0] mobile: '84357984375',
[0] updated: 2019-03-08T17:03:19.360Z,
[0] created: 2019-03-08T17:03:00.462Z,
[0] createdBy: 'Avinash Shetty',
[0] customerId: 87,
[0] __v: 1,
[0] updatedBy: 'Avinash Shetty' },
[0] { customerRequest: [ [Object] ],
[0] _id: 5c81a86afe50590ae86ee2d2,
[0] name: 'user3',
[0] mobile: '348753456',
[0] updated: 2019-03-07T23:26:45.676Z,
[0] created: 2019-03-07T23:25:30.173Z,
[0] createdBy: 'Avinash Shetty',
[0] customerId: 86,
[0] __v: 1,
[0] updatedBy: 'Avinash Shetty' },
上面的代码工作正常,但突然它停止获取数据。 axios.get的then子句中的Console.log返回
config: {adapter: ƒ, transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", …}
data: ""
headers: {strict-transport-security: "max-age=15552000; includeSubDomains", content-encoding: "gzip", x-content-type-options: "nosniff", access-control-allow-origin: "*", x-powered-by: "Express", …}
request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
status: 200
statusText: ""
__proto__: Object
过去两个月中,该代码运行良好。我还向客户展示了。突然,由于某种原因,它现在无法获取返回的数据。一旦出错,无论我做什么尝试,它都不会再次开始获取。
请指导,这里可能是什么问题。