【发布时间】:2019-07-09 18:54:50
【问题描述】:
尝试使用 axios 发出 http 请求,然后从请求中访问某些属性。属性未定义,尽管它存在
public getApiURL() {
axios.get('https://xxxxxxxxx.com/metadata.json')
.then(res => {
console.log(res.data); // {"apiUrl":"https://xxxx.com/Api"}
console.log(res.data.apiUrl); // undefined
}).catch(err => {
console.log('error', err);
})
}
【问题讨论】:
-
也许你必须做一个 JSON.parse(res.data).apiUrl
-
做
console.log(typeof res.data)
标签: javascript node.js axios