tencent cloud

All product documents
Tencent Cloud Super App as a Service
Custom component
Last updated: 2024-11-21 18:41:53
Custom component
Last updated: 2024-11-21 18:41:53

nextTick

The usage method of this API is wx.nextTick(function callback).
Feature Description: Defers certain operations to be executed in the next time slice, similar to the setTimeout feature.
Parameter and Description: The function callback is used because the setData and triggerEvent interfaces in custom components are inherently synchronous operations. When these interfaces are called consecutively, they are executed within a single synchronous process, which may lead to errors in the case of improper logic.
An extreme case: If the parent component's setData triggers the child component's triggerEvent, causing the parent component to perform setData again, and in the process, the child component is unloaded through the wx:if statement, this could potentially cause an error. Therefore, for logic that does not need to be completed within a single synchronous process, this interface can be used to defer execution to the next time slice.
Sample Code
Component({
doSth() {
this.setData({ number: 1 }) // Executed directly within the current synchronous process

wx.nextTick(() => {
this.setData({ number: 3 }) // Executed after the current synchronous process ends, in the next time slice.
})

this.setData({ number: 2 }) // Executed directly within the current synchronous process
}
})

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon