Below are examples of the Alpine.js directives we use to build storefront components. While these examples are self-contained and include all the data they need to run, it is worth mentioning that any data we make available in our API and any JavaScript you might dream up can be utilized in the same way.
For a full list of Alpine.js directives including shortcuts and detailed examples, please see the official documentation here: Alpine.js Docs
Current OS:
x_text
Sets the text that should be displayed for an element.
1
2
3
<divx-data="{ OS: navigator.platform }">
Current OS: <spanx-text="OS"></span></div>
x_on
Allows you to run javascript any time a dom event is fired. this lighthearted example makes heavy use of the click event, but keyboard clicks and other events can be captured as well.
Allows you to bind an input field to a variable. this binding is two-way, so changing the input field will update this variable, and changing this variable will overwrite and update the field.
Dynamically generates markup based on elements in a javascript array. it must be declared in a <template> tag and that <template> must have only one child element (though that child can have as many elements as you please).
1
2
3
4
5
6
<ulx-data=
"{ list: ['Free', 'Standard', 'Overnight'] }"><templatex-for="rate in list"><lix-text="rate"></li></template></ul>
Sales:
x_bind
Allows you to bind any html attribute to the result of a javascript expression.