Added
- The ability to return a callback from
x-init
and it will run AFTER Alpine makes it's initial DOM updates (similar to themounted()
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
andx-mounted
are now deprecated and will be removed in 2.0