i'm using alpine.js for my project and I have a modal that works well with alpine.js, my problem is that whenever you refresh the page, it shows for a second or two (while the page loads) and then goes away. I don't want to see it onload. Is there any way to workaround that in alpine.js?
My code
// Initialize data
<body x-data="{openModal: false}"
:class="openModal ? 'overflow-hidden' : 'overflow-visible'"
>
// button
<button @click="openModal = true">
Open Modal
</button>
<!-- Modal -->
<div x-show="openModal">
<!-- content -->
</div>
</body>
You're looking for the
x-cloakdirective.It's a very simple one, it gets removed from the component when Alpine starts up.
So in your case you can add the following
style(which will hide elements with thex-cloakattribute) and addx-cloakto your Alpine.js component (in this case thebody).