Creates a reactive structs with the help of the returned builder.
A reactive struct is a class like object that can contain properties, computed properties and methods.
By default all properties are reactive and writable.
Now, you can use the person instance for example to compute the person's full name.
constfullName = computed(() =>`${person.firstName}${person.lastName}`); console.log(fullName.value); // John Doe person.firstName = "Jane"; console.log(fullName.value); // Jane Doe
Options for simple properties
The following options can be set for properties in the struct definition:
writable: if true the property is writable and it can be changed (the default). If false the property is read-only.
reactive: if true the property is reactive (the default). If false the property is not reactive.
To define a read-only property set writable to false:
NOTE:
All strings or symbols are allowed as property names, except for strings starting with '$'.
Strings starting with '$' are reserved for future extensions.
Creates a reactive structs with the help of the returned builder.
A reactive struct is a class like object that can contain properties, computed properties and methods. By default all properties are reactive and writable.
Create a reactive struct
To create a reactive struct proceed as follows:
Define the type of the struct.
Create a definition for the struct according to the type.
Create a new reactive struct class based on the provided definition.
Create a new instance of the struct.
Use the created instance.
Now, you can use the person instance for example to compute the person's full name.
Options for simple properties
The following options can be set for properties in the struct definition:
writable
: iftrue
the property is writable and it can be changed (the default). Iffalse
the property is read-only.reactive
: iftrue
the property is reactive (the default). Iffalse
the property is not reactive.To define a read-only property set
writable
tofalse
:To define a non reactive property set
reactive
tofalse
:Computed properties
Computed properties are properties that are computed based on other properties. They can be defined in the struct definition as follows:
Methods
You can also define methods in the struct definition: