我想将我从诺言收到的response.data存储在一个变量中。
function testingFunction () {
return axios.post("https://secure.meetup.com/oauth2/access", meetupObjectToSend, config)
.then(response => {
console.log(response.data)
return response.data
})
.catch(error => {
console.log(error)
})
}
我这样称呼:
letSomeData = testingFunction()
当我做console.log(SomeData)
setTimeout(function(){ console.log(letSomeData) }, 5000);
我的响应被嵌套在Promise对象下,即上面的控制台登录超时,记录了以下内容:
Promise {
{ access_token: 'eb42c6b0a8aa3fn01d5ae45f',
refresh_token: '4dcfda447eacbf5ddj6d391192',
token_type: 'bearer',
expires_in: 3600 } }
console.log中的promise(response.data),
axios.post("https://secure.meetup.com/oauth2/access", meetupObjectToSend, config)
.then(response => {
console.log(response.data)
仅记录以下内容:
{ access_token: 'eb42c6b0a8aa3fn01d5ae45f',
refresh_token: '4dcfda447eacbf5ddj6d391192',
token_type: 'bearer',
expires_in: 3600 }
所以,为什么我的结果嵌套在promise对象中,并且如何使其不嵌套在promise对象中?