I'm wondering if there's a way of use the $nextTick AlpineJS magic property in a javascript script (the "$nextTick" is not recognize):
<div x-data="{ app() }">
<button
@click="updateContent"
x-text="title"
></button>
</div>
...
<script src="{{ asset('js/my_script.js') }}"></script>
my_script.js:
function app() {
return {
title: 'Hello',
updateContent: function() {
title = 'Hello World!';
// $nextTick(() => { console.log($el.innerText) });
// $ is not recognize
}
}
}
This works for me:
Alpine.nextTick()
Like this:
export function example() {
return {
open() {
...
Alpine.nextTick(() => {
document.querySelector('#menu a')?.focus();
});
...
},
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With