react,本地开发数据获取问题?

使用postman能成功获取到本地数据库里的数据:

img


已写的获取数据的部分代码如下:

const res = axios.get('http://localhost:8080/area/city?level=1')
console.log(res)
console.log(res.data)
console.log(res.data.body)
console.log(res.data.body.label)

打印res后显示:

img


请问为何打印res.data、res.data.body、res.data.body.label后均显示undifined?请问是有代码漏写了吗?

axios.get('http://localhost:8080/area/city?level=1').then(res=>{
  console.log(res)
 })

axios.get是异步方法,返回的是promise,参考文档:https://www.axios-http.cn/docs/example

加个.then((res)=>{console.log(res)})


  async  function api(){
        const res = await axios.get('http://localhost:8080/area/city?level=1')
        console.log(res)
        console.log(res.data)
        console.log(res.data.body)
        console.log(res.data.body.label)
    }

或者

    axios.get('http://localhost:8080/area/city?level=1').then(res=>{
            console.log(res)
            console.log(res.data)
            console.log(res.data.body)
            console.log(res.data.body.label)
        }).catch(err=>{

        })

知识点 :Promise,async ,await