Skip to content

$store

You can use $store to conveniently access global Alpine stores registered using Alpine.store(...) (covered in the next page). For example:

html
<button x-data @click="$store.darkMode.toggle()">Toggle Dark Mode</button>
 
...
 
<div x-data :class="$store.darkMode.on && 'bg-black'">
    ...
</div>
 
 
<script>
    document.addEventListener('alpine:init', () => {
        Alpine.store('darkMode', {
            on: false,
 
            toggle() {
                this.on = ! this.on
            }
        })
    })
</script>