Cosen95 / fe_interview

字节、阿里、美团、滴滴、腾讯等大厂高级前端面试题整理
238 stars 25 forks source link

Vue中是如何检测数组变化的? #95

Open Cosen95 opened 4 years ago

Cosen95 commented 4 years ago

Vue中检测数组变化核心有两点:

这里用一张流程图来说明:

这里第一步和第二步和上题请说一下响应式数据的原理?是相同的,就不展开说明了。

import { def } from '../util/index'

const arrayProto = Array.prototype export const arrayMethods = Object.create(arrayProto)

const methodsToPatch = [ // 这里列举的数组的方法是调用后能改变原数组的 'push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse' ]

/**