Skip to content
Advertisement

How to change shared state in Alpine.js?

I’m trying to hide multiple elements inside the DOM by changing shared state when window is resized.

JavaScript

And when i try to

JavaScript

It should change the state ** hideOnMobile** to true but it doesn’t somehow any idea?

Advertisement

Answer

Have you tried using @resize.window? (ie. adding the resize listener using Alpine.js) it should make your code simpler than using window.onresize + trying to update Alpine.js __x.$data internal.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement