从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