pilotwings/frontend/views/Home.vue

46 lines
1.0 KiB
Vue
Raw Normal View History

<template>
<Loading class="container" :loading="loading">
2024-11-03 18:14:47 +00:00
<Message v-if="error" type="danger">{{ error }}</Message>
<ul v-if="!loading && !error">
2024-11-03 18:14:47 +00:00
<li v-for="container in containers" :key="container">
<router-link :to="`/container/${container}`">
{{ container }}
</router-link>
</li>
</ul>
</Loading>
</template>
<script lang="ts">
2024-11-03 18:14:47 +00:00
import axios, { AxiosError } from 'axios'
import Loading from '@/components/Loading.vue'
import Message from '@/components/Message.vue'
export default {
name: 'Home',
components: {
Loading,
Message,
},
data() {
return {
2024-11-03 18:14:47 +00:00
containers: [] as string[],
error: '',
loading: true,
}
},
async mounted() {
try {
2024-11-03 18:14:47 +00:00
const response = await axios.get<string[]>('/api/containers')
this.containers = response.data
} catch (error) {
console.error(error)
2024-11-03 18:14:47 +00:00
this.error =
error instanceof AxiosError ? error.message : 'Error loading containers'
} finally {
this.loading = false
}
},
}
</script>