...

/

Declare Our Website Data: x-data

Declare Our Website Data: x-data

Learn to use the `x-data` attribute to declare data required by the AlpineJS component.

Unlike vanilla JavaScript, most AlpineJS directives and constructs only work in an AlpineJS component. That means we can only access them within a component. An AlpineJS component is a chunk of HTML marked with x-data.

Declare an AlpineJS component

We define AlpineJS components using the x-data directive. This is the first thing we find in an AlpineJS component. Mostly, we define x-data in a wrapper element. It makes properties in x-data available to the children ...