github alpinejs/alpine v1.7.0
on GitHub

Added

  • The ability to return a callback from x-init and it will run AFTER Alpine makes it’s initial DOM updates (similar to the mounted() hook in VueJS, or the current, but now deprecated, x-mounted hook)

    <div x-data="initialData()" x-init="init()">
    <span x-text="foo" x-ref="span">bar</span>
    </div>
    <script>
    function initialData() {
    return {
        foo: 'baz',
        init() {
            this.$refs.span.innerText // 'bar'
    
    
            return () => {
                this.$refs.span.innerText // 'baz'
            }
        }
    }
    }
    </script>
    

    Deprecated

    • x-created and x-mounted are now deprecated and will be removed in 2.0
7 months ago