has.nextTick(function callback)
Defers a set of operations to the next execution tick.
Its function is similar to that of setTimeout.
APIs like setData in custom components are inherently synchronous. When these APIs are called consecutively, they are executed within the same synchronous process. Improper logical handling in this process may lead to errors.
Edge case example: Unusual errors may occur if a parent component's setData triggers a child component's triggerEvent, which in turn causes the parent component to execute setData again, and if the child component is unloaded via the has:if statement during this process. Therefore, for logic that does not need to be completed within the same synchronous process, this API can be used to defer its execution to the next tick.
Since: 1.0.14
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | Yes | Callback to be deferred. |
Example:
this.setData({ number: 1 }); // Executed immediately in the current synchronous process.
has.nextTick(() => {
this.setData({ number: 3 }); // Executed in the next tick after the current synchronous process completes.
});
this.setData({ number: 2 }); // Executed immediately in the current synchronous process.