Vue3 reactive 之源码的实现
Reflect.get()方法与从 对象 (target[propertyKey]) 中读取属性类似,但它是通过一个函数执行来操作的。
export const reactive = <T extends object>(target: T) => {
return new Proxy(target, {
get(target, key, receiver) {
const res = Reflect.get(target, key, receiver)
return res
},
set(target, key, receiver) {
const res = Reflect.get(target, key, receiver)
return res
}
})
}
reactive({})