本文是对 vue 2.6.14 版本的 nextTick的解读。
首先download源码,然后进入文件 src\core\index.js
import Vue from './instance/index'
import { initGlobalAPI } from './global-api/index'
import { isServerRendering } from 'core/util/env'
import { FunctionalRenderContext } from 'core/vdom/create-functional-component'
initGlobalAPI(Vue)
随后 打开文件 src\core\global-api\index.js 里面的44-46行代码为:
Vue.set = set
Vue.delete = del
Vue.nextTick = nextTick
找到 nextTick 来源于文件 src\core\util\next-tick.js 。
阅读源码:
/* @flow */
/* globals MutationObserver */
import { noop } from 'shared/util'
import { handleError } from './error'
import { isIE, isIOS, isNative } from './env'
export let isUsingMicroTask = false
const callbacks = []
let pending = fa