我在從 api 呼叫訪問嵌套資料時遇到問題。JSON 回應如下所示:

我嘗試訪問屬性中的 attribute_name。和語言中的語言名稱。我可以使用以下代碼顯示 location_name {{ userdetails.location.location_name }}
我總是遇到嵌套 api 資料的問題。是否有指南如何從 api 訪問資料?
謝謝!
更新:我的代碼看起來像這樣
data() {
return {
userdetails: undefined,
};
},
methods: {
getUserData() {
DataService.getUserById()
.then((response) => {
this.userdetails = response.data;
console.log(response);
})
.catch((error) => {
console.log(
"Ein Fehler beim User ist aufgetreten: " error.response
);
});
},
},
created() {
this.getUserData();
},
};
uj5u.com熱心網友回復:
attributes屬性是陣列所以嘗試(index是陣列中的索引):
{{ userdetails.attributes[index].attribute_name }}
如果你想把它們全部展示出來:
<div v-for="(attr, i) in userdetails.attributes" :key="i" >
{{ attr.attribute_name }}
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/371633.html
