从
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)