从对象数组获取数据的问题 - vue.js / API / axios / proxy
Issue with getting data from an array of objects - vue.js / API / axios / proxy
首先,我使用 Vue.js 通过 axios 和代理访问 API 的数据
我正在尝试访问嵌套在其他几个数组的最后一个数组中的对象的 属性,但我有点碰壁,这里是详细信息:
Global details
the property I'm trying to access
我尝试过不同的方法,但这是我最近的尝试:
axios
.get(proxyurl + history_url, {
reqHeaders
})
.then((reponse) => {
console.log(reponse.data)
this.lastItem = reponse.data.data.history[history.length-1]
console.log(this.lastItem)
this.lastEvol = this.lastItem.price
console.log(this.lastEvol)
})
这里的问题是“console.log(this.lastItem)”的答案是:
lastItem answer
属性值现在不同且不正确。
由于它显示“代理”作为根对象名称,我认为这可能是问题所在,但我不确定。
我尝试了其他几种方法来访问此 属性 但只有错误。
如有任何帮助,我们将不胜感激。
history
在 history.length
表达式中未定义。试试这个:
.then((reponse) => {
const history = reponse.data.data.history;
console.log(reponse.data)
this.lastItem = history[history.length-1]
console.log(this.lastItem)
this.lastEvol = this.lastItem.price
console.log(this.lastEvol)
})
首先,我使用 Vue.js 通过 axios 和代理访问 API 的数据 我正在尝试访问嵌套在其他几个数组的最后一个数组中的对象的 属性,但我有点碰壁,这里是详细信息:
Global details
the property I'm trying to access
我尝试过不同的方法,但这是我最近的尝试:
axios
.get(proxyurl + history_url, {
reqHeaders
})
.then((reponse) => {
console.log(reponse.data)
this.lastItem = reponse.data.data.history[history.length-1]
console.log(this.lastItem)
this.lastEvol = this.lastItem.price
console.log(this.lastEvol)
})
这里的问题是“console.log(this.lastItem)”的答案是:
lastItem answer
属性值现在不同且不正确。 由于它显示“代理”作为根对象名称,我认为这可能是问题所在,但我不确定。
我尝试了其他几种方法来访问此 属性 但只有错误。
如有任何帮助,我们将不胜感激。
history
在 history.length
表达式中未定义。试试这个:
.then((reponse) => {
const history = reponse.data.data.history;
console.log(reponse.data)
this.lastItem = history[history.length-1]
console.log(this.lastItem)
this.lastEvol = this.lastItem.price
console.log(this.lastEvol)
})