我尝试让这段代码工作。
const axios = require('axios');
let bodyapi = axios.get('there's my api')
console.log(bodyapi.data) <- undefined
let body = bodyapi.data
console.log(body.discord) <- couldn't get parameter ''discord'' of undefined
API的响应类型:
"discord":{"Category":"activation","Qty":1542,"Price":1}
"vkontakte":{"Category":"activation","Qty":133,"Price":21}
我得到它“未定义”。在 NodeJS 上运行。
最佳答案
axios 返回 promise
const axios = require('axios');
// use async await
(async ()=>{
let bodyapi = await axios.get('there's my api')
console.log(bodyapi.data) // response
})()
// other way
axios.get('there's my api').then(data=> console.log(data))
关于javascript - NodeJS Axios 响应在 console.log API 上未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59963550/