Alpine Test XINIT
x-data The x-init directive allows you to hook into the initialization phase of any element in Alpine.
Unlike Vue, Alpine doesn’t provide any explicit lifecycle hooks.
However, you can achieve two of Vue’s lifecycle hooks - created and mounted - in Alpine using the x-init directive.
The x-init directive is used to execute some JavaScript when a component is initialized. This can range from simple expressions to complex functions. Think of it as created hooks for Vue.
To achieve Vue’s mounted hook, you can return a callback from x-init, which will be run after Alpine has made its initial updates to the DOM.