深度代理
This commit is contained in:
parent
4a25e83d14
commit
e9f891cf15
@ -99,3 +99,20 @@ export function Dialog(options) {
|
|||||||
element.onremove = () => observer.disconnect()
|
element.onremove = () => observer.disconnect()
|
||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 深度代理, 用于监听数据的变化
|
||||||
|
export function useProxy(obj, callback) {
|
||||||
|
return new Proxy(obj, {
|
||||||
|
get(target, key) {
|
||||||
|
if (typeof target[key] === 'object' && target[key] !== null) {
|
||||||
|
return useProxy(target[key], callback)
|
||||||
|
}
|
||||||
|
return target[key]
|
||||||
|
},
|
||||||
|
set(target, key, value) {
|
||||||
|
target[key] = value
|
||||||
|
callback(target, key, value)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user