你好,我正在使用一個api,其回傳結果如下
。{"secret-finance"/span>。 {"usd":0. 04883396}}
問題是我在使用vue,并像這樣檢索資料
。async getCurrentSefiPrice() {
await axios
.get(
"https://api.coingecko.com/api/v3/simple/price?ids=secret-finance&vs_currencies=usd"/span>
)
.then(
(response) =>。
(this.sefi_token_current_price = response.secret-finance.usd)
// console.log(response)
);
console.log(this.sefi_token_current_price)。
}
但是當我使用secret-finance來獲取美元價值時,我得到了一個錯誤。
謝謝你的幫助。
uj5u.com熱心網友回復:
@haseebsaeed 你需要將其參考為
response["secret-finance"].usd
當一個鍵中有一個連字符時,你需要使用鍵的符號而不是點的概念。任何包含JavaScript變數所不允許的字符的鍵,你都需要像上面那樣參考它們。
再舉一個例子。
如果secret-finance物件有一個us-dollars的屬性鍵,而不是當前的usd,那么你將通過以下方式來訪問它:
response["secret-finance"]["us-dollars"]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/326902.html
標籤:
