|
|
@@ -1,5 +1,5 @@
|
|
|
<script setup>
|
|
|
-import { computed, onMounted, ref } from "vue";
|
|
|
+import { computed, ref, watch } from "vue";
|
|
|
import { useRoute, useRouter } from "vue-router";
|
|
|
import LayoutSistema from "../../layout/LayoutSistema.vue";
|
|
|
import BaseBadge from "../../components/base/BaseBadge.vue";
|
|
|
@@ -93,15 +93,22 @@ function novoDia(idx) {
|
|
|
return new Date(atual).toDateString() !== new Date(anterior).toDateString();
|
|
|
}
|
|
|
|
|
|
-onMounted(async () => {
|
|
|
+async function carregar(id) {
|
|
|
+ carregando.value = true;
|
|
|
+ erro.value = "";
|
|
|
+ atendimento.value = null;
|
|
|
try {
|
|
|
- atendimento.value = await obterAtendimento(route.params.id);
|
|
|
+ atendimento.value = await obterAtendimento(id);
|
|
|
} catch (err) {
|
|
|
erro.value = err?.message ?? "Falha ao carregar o atendimento";
|
|
|
} finally {
|
|
|
carregando.value = false;
|
|
|
}
|
|
|
-});
|
|
|
+}
|
|
|
+
|
|
|
+// watch (em vez de onMounted) porque o Vue Router reaproveita esta instância quando se
|
|
|
+// navega entre duas URLs /atendimentos/:id sem desmontar o componente
|
|
|
+watch(() => route.params.id, carregar, { immediate: true });
|
|
|
</script>
|
|
|
|
|
|
<template>
|