Access x-data from outside Alpine #4425
-
How can I access x-data from outside Alpine?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Generally, you shouldn't. For what purpose do you have the need for this? There can be multiple ways to expose data to other code, and the best way to do that is informed by what exactly the goal is. Do you have more of an example that demonstrates the need? This code here does not demonstrate a need. |
Beta Was this translation helpful? Give feedback.
-
Sure. I'm trying to use Alpine together with htmx. I want to pass x-data back to server using the htmx attribute hx-vals (https://htmx.org/attributes/hx-vals/) |
Beta Was this translation helpful? Give feedback.
-
OK, thank you |
Beta Was this translation helpful? Give feedback.
Then you can do
:hx-vals="JSON.stringify($data)"
It was doing exactly that that led me to need to make this PR to htmx bigskysoftware/htmx#2799