Skip to content

Having issues with hydration directive and script setup #125

Answered by ElMassimo
rylanharper asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Rylan,

This is something that the Client Scripts doesn't mention explicitly, but anything that you define in a Client Script is essentially separate from the Vue component, it will just be injected next to where it's rendered. It's an alternative to islands, where you need client-side code that does not map to a component.

The hydration directives should not be used in <script setup> but in a separate plain script tag, and you wouldn't be ableto share state or methods, since they are running in different contexts (script setup runs when building the site, the client script runs in the browser).


I'd recommend not using Pinia in client scripts, and instead simplify and use plain ref ins…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants