Response.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <div class="flex flex-col flex-1">
  3. <HttpResponseMeta :response="response" />
  4. <LensesResponseBodyRenderer
  5. v-if="!loading && hasResponse"
  6. :response="response"
  7. />
  8. </div>
  9. </template>
  10. <script lang="ts">
  11. import { computed, defineComponent, watch } from "@nuxtjs/composition-api"
  12. import { useNuxt, useReadonlyStream } from "~/helpers/utils/composables"
  13. import { restResponse$ } from "~/newstore/RESTSession"
  14. export default defineComponent({
  15. setup() {
  16. const response = useReadonlyStream(restResponse$, null)
  17. const hasResponse = computed(
  18. () =>
  19. response.value?.type === "success" || response.value?.type === "fail"
  20. )
  21. const loading = computed(
  22. () => response.value === null || response.value.type === "loading"
  23. )
  24. const nuxt = useNuxt()
  25. watch(response, () => {
  26. if (response.value?.type === "loading") nuxt.value.$loading.start()
  27. else nuxt.value.$loading.finish()
  28. })
  29. return {
  30. hasResponse,
  31. response,
  32. loading,
  33. }
  34. },
  35. })
  36. </script>