parent
2aa9ab5af0
commit
0483d6efc3
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "wkit",
|
"name": "wkit",
|
||||||
"version": "1.10.5",
|
"version": "1.10.6",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "A library for building fast, lightweight web components.",
|
"description": "A library for building fast, lightweight web components.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
12
src/index.js
12
src/index.js
|
@ -201,12 +201,20 @@ export class Component extends HTMLElement {
|
||||||
|
|
||||||
#createProxy(name, options, newValue) {
|
#createProxy(name, options, newValue) {
|
||||||
return new Proxy(newValue || options.default, {
|
return new Proxy(newValue || options.default, {
|
||||||
set: (target, prop, value) => {
|
get: (target, prop, receiver) => {
|
||||||
|
let value = Reflect.get(target, prop, receiver)
|
||||||
|
// 当访问的值是对象时,需要对这个对象也进行代理
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
return this.#createProxy(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
},
|
||||||
|
set: (target, prop, value, receiver) => {
|
||||||
if (prop === 'length' && options.type === Array) {
|
if (prop === 'length' && options.type === Array) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
let oldValue = target[prop]
|
let oldValue = target[prop]
|
||||||
target[prop] = value
|
Reflect.set(target, key, value, receiver)
|
||||||
|
|
||||||
this.$requestUpdate(name)
|
this.$requestUpdate(name)
|
||||||
if (options.observer) {
|
if (options.observer) {
|
||||||
|
|
Loading…
Reference in New Issue