Isolated and special variables
To create a component that renders values in isolation in each rendering we must pass a second argument to the function that creates components, this must be an object with the properties that will be isolated:
These properties behave like isolated variables for each component render.
We will now refer to these variables as
compVars
(component variables)
Handling compVars
After creating the component and the compVars
they are available through an object and accessible by the $
symbol, with which we can access, change the values of the properties and add others.
This is a special object that can only be used in known callbacks of the component instance, it will normally be used in Hooks and in callbacks in DOM events.
The responsibility of this object is to keep the values isolated for each rendering of the component and only when necessary to create clones of data structures such as Array, Map, Set and Object.
Using compVars in the template
To use compVars
in the template we will use a special shortcut, using $
plus the property name/path:
To mark the property as optional just add a ?
to the end:
Variables that are attributes
If a variable has the same name as an attribute and its value is intended for it, we can use the @
and the variable name so that it is used as the attribute name and value:
Last updated