tencent cloud

Feedback

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
    }
    })
    
    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 avaliable.

    7x24 Phone Support