Data Properties

The state of the our components.

Components have state known as Data Properties.

Data Properties are defined by creating a data structure on your component and assigning each property a default value.

<!--- ./wires/SomeComponent.cfm --->
<cfscript>
    data = {
        "propertyName": "defaultValue"
    };
</cfscript>

Property names must be surrounded by single or double quotes.

JavaScript is a case-sensitive language and CFML isn't. To preserve the casing of your property names, you must surround them with quotes.

// Bad
data = {
    propertyName: "defaultValue"
};

// Good
data = {
    "propertyName": "defaultValue"
};

Data Properties are parsed by JavaScript and therefore can only store values that are JavaScript friendly: strings, numeric, arrays, structs, or booleans.

Initial Values

Data properties should be assigned a default value, even if it's just an empty string.

Using Data Properties

You can access Data Properties from within your component Actions like so.

You can also reference Data Properties within your component template using #propertyName#.

Resetting Data Properties

You can reset properties back to their original value inside your Actions using reset().

You can reset individual or all Data Properties.

You also can reset all properties EXCEPT the properties you pass.

Data Binding

You can bind your data properties and HTML elements using wire:model.

There are also several modifiers you can add to control when and how requests are sent to your server.

Last updated