高级前端
vue
【Q450】Vue 中 nextTick 的实现原理是什么

Vue 中 nextTick 的实现原理是什么

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 458 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

  • Promise
  • MutationObserver
  • setImmediate
  • setTimeout

Author 回答者: wangenze267 (opens in a new tab)

nextTick方法主要是使用了宏任务和微任务。它是定义了一个异步方法,如果多次调用nextTick的话,就会将方法存入队列中,通过这个异步方法来清空当前队列,这个nextTick方法就是异步方法