<template>
<div class="max-w-sm rounded overflow-hidden shadow-lg bg-white">
<div class="px-6 py-4">
<div class="font-bold text-xl mb-2">{{coin.data.name}} Price Statistics</div>
<table class="table-fixed">
<tbody>
<tr>
<th>Price</th>
<td>{{coin.data.market_data.current_price.usd}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script setup>
import { api } from '../services/api'
import { reactive } from 'vue'
const props = defineProps(['coinId'])
const coin = reactive({
data: []
});
async function fetchData() {
try {
coin.data = await api.get(`/coins/${props.coinId}`)
.then((response) => {
return response.data;
})
}
catch (e) {
console.error(e)
}
}
fetchData()
</script>
Hey guys, i'm struggling a lot trying to read data from an api. So, im reading this data from coingecko and when it's just on the first array it works very well. But when its an array inside an array its returns undefined when i try to refresh the page. But while i'm coding and it auto updates, it works very well. How can i treat it and make it so it doesn't show up undefined before anything?