I'm using a store for a modal and like to use the magic $watch method like so:
Alpine.store('modal', {
init() {
this.$watch('this.open', (val) => console.log(val))
// Here I like to do if(open) { document.body.classList.add('overflow-hidden') }
},
open: false,
id: null,
close() {
this.open = false
this.id = null
}
})
But I get TypeError: this.$watch is not a function
x-data :class="{ 'overflow-hidden': $store.modal.open }"to your body element.openvalue so that I can add a class to the body. I don't want to add anx-dataon the body.open() { this.open = true; document.body.classList.add('overflow-hidden') }. I never tried this in an external component. Not sure if thedocumentobject works like this here.