使用postman能成功获取到本地数据库里的数据:
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后显示:
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