Add ResourceButton component; refactoring
Some checks failed
/ build (push) Failing after 8s

This commit is contained in:
phil 2025-02-13 12:21:25 +01:00
parent 532c2f1f6f
commit d3943fc0b2
3 changed files with 101 additions and 57 deletions

34
src/ResourceButton.vue Normal file
View file

@ -0,0 +1,34 @@
<script setup lang='ts'>
import { ref } from 'vue'
import { resourceServer } from '@/main'
const props = defineProps({
resourceName: String,
resourceId: String,
})
let _class: String = ref("")
let _title: String = ref("")
const init = async (props) => {
const url = props.resourceId ? `${props.resourceName}/${props.resourceId}` : props.resourceName
await resourceServer.get(url).then(
resp => {
_class.value = `hasResponseStatus status-${resp.status}`
_title.value = `Response code: ${resp.status} - ${resp.statusText}`
}
).catch(
err => {
_class.value = `hasResponseStatus status-${err.response.status}`
_title.value = `Response code: ${err.response.status} - ${err.response.statusText}`
}
)
}
init(props);
</script>
<template>
<button :class="_class" :title="_title" @click="$emit('getResource', $event)"></button>
</template>