Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Promise.all Error:Uncaught(in Promise)TypeError:#<;承诺>;这是不可容忍的_Javascript_Reactjs_Promise - Fatal编程技术网

Javascript Promise.all Error:Uncaught(in Promise)TypeError:#<;承诺>;这是不可容忍的

Javascript Promise.all Error:Uncaught(in Promise)TypeError:#<;承诺>;这是不可容忍的,javascript,reactjs,promise,Javascript,Reactjs,Promise,因此,我需要点击2个API,并等待这两个响应返回,然后再发送操作 我正在使用Promise。但是所有都遇到以下错误: index.js:51未捕获(承诺中)类型错误:#不可编辑 at Function.all() 承诺。所有都接受一组承诺,而不是参数列表中依次列出的承诺。改为: const fetchAll = () => Promise.all([ fetchPrices(), fetchSupplies() ]); 注意 .then((resultsArray) =>

因此,我需要点击2个API,并等待这两个响应返回,然后再发送操作

我正在使用
Promise。但是所有
都遇到以下错误:

index.js:51未捕获(承诺中)类型错误:#不可编辑 at Function.all()


承诺。所有
都接受一组
承诺
,而不是参数列表中依次列出的
承诺
。改为:

const fetchAll = () => Promise.all([
  fetchPrices(),
  fetchSupplies()
]);
注意

.then((resultsArray) => {
  return resultsArray;
});
是多余的;现有的
Promise
解析为一个结果数组,因此调用
。然后
将另一个
Promise
链接到该数组上,该数组接受该结果并解析为该数组,没有任何用处;你可以完全不谈

另外,不需要使用
Promise.resolve
-我不知道
getPrices
getSupply
返回什么,但是如果将非承诺传递到
Promise.all
,则不会抛出错误,结果数组将只包含这些值。(如果承诺被返回,则当所有此类承诺都已解决时,
Promise.all
将解决。)因此,您可以执行以下操作:

const fetchAll = () => Promise.all([
  getPrices(),
  getSupply()
]);
(当然,如果
getPrices
getSupply
都返回非承诺,那么就不需要
Promise.all

const fetchAll = () => Promise.all([
  getPrices(),
  getSupply()
]);