从Axios API返回数据

从Axios API返回数据,第1张

从Axios API返回数据

axiosTest
函数中的axios调用返回promise ,然后在使用另一个调用它时从promise中获取值
.then

function axiosTest() {  return axios.get(url).then(response => {    // returning the data here allows the caller to get it through another .then(...)    return response.data  })}axiosTest()  .then(data => {    response.json({ message: 'Request received!', data })  })  .catch(err => console.log(err))

我还建议您阅读有关诺言如何工作的更多信息:https : //developer.mozilla.org/en-
US/docs/Web/Javascript/Guide/Using_promises



欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/5642245.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存