About nextTick

Why did it appear? In what scenario is it used?

(1) Vue updates the DOM asynchronously. When the data changes, the DOM update will not be completed immediately. The nextTick callback is a delayed callback executed after the next DOM update cycle ends.

(2) nextTick will be used in the following cases:

1. When an operation is performed after the data changes, and this operation needs to use the DOM structure that changes with the data change, this operation needs to be in the callback function of nextTick().

2. In the vue life cycle, if the DOM operation is performed in the created() hook, it must also be placed in the callback function of nextTick(). (Because in the created() hook function, the DOM of the page has not been rendered, and there is no way to operate the DOM at this time, so if you want to operate the DOM at this time, you must put the operation code in the callback function of nextTick())


 

Guess you like

Origin blog.csdn.net/qq_46617584/article/details/131658905