oidc-vue-test/src/ResourceButton.vue

35 lines
954 B
Vue
Raw Normal View History

<script setup lang='ts'>
2025-02-13 15:12:17 +01:00
import { ref, type PropType } from 'vue'
import { resourceServer } from '@/main'
2025-02-13 15:12:17 +01:00
const props: { [key: string]: String} = defineProps({
resourceName: String,
resourceId: String,
})
2025-02-13 15:12:17 +01:00
let _class = ref<string>("")
let _title = ref<string>("")
2025-02-13 15:12:17 +01:00
const init = async (props: { [id: string]: any}) => {
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>