<template>
<h1 class="text-lg text-gray-400 font-medium">Tracker dashboard</h1>
<div class="flex flex-col mt-2 w-3/4">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden sm:rounded-lg">
<table class="min-w-full text-sm text-gray-400">
<thead class="bg-gray-800 text-xs uppercase font-medium">
<tr>
<th></th>
<th scope="col" class="px-6 py-3 text-left tracking-wider">
Coin
</th>
<th scope="col" class="px-6 py-3 text-left tracking-wider">
Price
</th>
<th scope="col" class="px-6 py-3 text-left tracking-wider">
24h
</th>
<th scope="col" class="px-6 py-3 text-left tracking-wider">
7d
</th>
<th scope="col" class="px-6 py-3 text-left tracking-wider">
30d
</th>
<th scope="col" class="px-6 py-3 text-left tracking-wider">
market cap
</th>
</tr>
</thead>
<tbody v-for="(item, index) in list.coinsList" class="bg-gray-800">
<tr class="bg-black bg-opacity-20">
<td class="pl-4">
{{ index + 1}}
</td>
<td class="flex px-6 py-4 whitespace-nowrap">
<img class="w-5" :src="images[index]">
<span class="ml-2 font-medium">{{coins[index]}}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
${{ item.current_price.usd }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
{{ item.price_change_percentage_24h }}%
</td>
<td class="px-6 py-4 whitespace-nowrap">
{{ item.price_change_percentage_7d }}%
</td>
<td class="px-6 py-4 whitespace-nowrap">
{{ item.price_change_percentage_30d }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
${{ item.market_cap.usd }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { reactive } from 'vue'
import { api } from '../services/api'
import bitcoinImg from "../assets/bitcoin.png"
import dacxiImg from "../assets/dacxi.png"
import ethImg from "../assets/ethereum.png"
import atomImg from "../assets/atom.png"
import lunaImg from "../assets/luna.png"
const coins = ['bitcoin', 'dacxi', 'ethereum', 'cosmos', 'terra-luna-2']
const images = [bitcoinImg, dacxiImg, ethImg, atomImg, lunaImg]
const list = reactive({
coinsList: [],
});
coins.forEach((item) => {
api.get(`/coins/${item}`)
.then((response) => {
list.coinsList.push(response.data.market_data)
})
})
</script>
Hi everyone, I'm exploring Vue and encountering a challenge with this code. I'm looking for a more efficient approach. I attempted using onMounted but didn't achieve the desired outcome. How can I prevent the list from displaying out of order at times? Additionally, what steps can I take to incorporate the name and images into the JSON to avoid displaying them in the incorrect order?