例如
export function asyncAdd ( data ) {
return ({
type: 'ADD',
payload: (async () => {
fetch('http://add.com').then(( response ) => {
return response;
})
})()
// payload: new Promise(resolve => {
// fetch('http://add.com').then(response => {
// resolve();
// });
// })
})
}
发现直接 使用 async 返回的 Promise 会导致立即执行了 ADD_FULFILLED。
而使用 new Promise 是正常的异步返回。
请问 如果需要使用 async 函数应该如何 注册 payload ?
async/await
这两个是配对使用的,如果没有 await 是不会等待的参考:
https://developer.mozilla.org...
https://developer.mozilla.org...