Vue components let you build interactive parts of a website. Using them in Astro helps combine Vue's power with Astro's fast page loading.
Vue components in Astro
--- import MyVueComponent from '../components/MyVueComponent.vue'; --- <MyVueComponent client:load />
Use import to bring your Vue component into the Astro file.
Add client:load or other client directives to tell Astro when to load the Vue component in the browser.
Counter Vue component when the page loads in the browser.--- import Counter from '../components/Counter.vue'; --- <Counter client:load />
--- import InteractiveButton from '../components/InteractiveButton.vue'; --- <InteractiveButton client:idle />
--- import Modal from '../components/Modal.vue'; --- <Modal client:visible />
This Astro page imports a Vue component called ClickCounter. The component will load in the browser when the page loads, letting users click a button that updates a count.
--- import ClickCounter from '../components/ClickCounter.vue'; --- <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Vue in Astro Example</title> </head> <body> <h1>Click the button below:</h1> <ClickCounter client:load /> </body> </html>
Astro supports different client directives like client:load, client:idle, and client:visible to control when Vue components load.
Make sure your Vue components are in the correct folder and have the .vue extension.
Use browser DevTools to check if Vue components load and work as expected.
Vue components add interactivity inside Astro pages.
Import Vue components and use client directives to control loading.
This helps combine fast static sites with dynamic features.