0

I have the following astro page:

---
import BaseLayout from '../../layouts/BaseLayout.astro';
import ListadoProfesionales from "../../components/pages/ListadoProfesionales/ListadoProfesionales.vue";

---
<BaseLayout title="Listado de profesionales">
    <main class="container py-6">
        <ListadoProfesionales client:only="vue" />
    </main>
</BaseLayout>

The framework component "ListadoProfesionales" is rendering only in the browser with VueJS.

How can I show a Spinner (or a loading UI element) while AstroJS is fetching and rendering that component?

2
  • This may be useful: stackoverflow.com/a/75274563/19811221 In that first example, you could use a spinner element that you manually hide once your Vue component mounts. Commented Nov 25, 2023 at 19:53
  • And how I know when the component is mounted from an Astro page? Commented Nov 26, 2023 at 6:06

1 Answer 1

1

You can have a separate spinner element which is removed or hidden once the framework component loads.

For Vue, one way you could do it is like this:

.astro

<div class="spinner">Spinner Here</div>
<Vue client:only="vue" />

.vue component

<script setup>
import { ref, onMounted } from "vue";

const count = ref(0);

onMounted(() => {
  // Since the component in this example is basic, the spinner only briefly shows
  const spinner = document.querySelector(".spinner");
  spinner.remove();
});
</script>

<template>
  <button @click="count++">You clicked me {{ count }} times.</button>
</template>

So once the component mounts on Vue's side, remove the spinner from the DOM. You may need to do things differently depending on your component.

Sign up to request clarification or add additional context in comments.

1 Comment

The proper way to do this is shown in the Astro docs: docs.astro.build/en/reference/directives-reference/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.