We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当前 issue 主要是讨论在低版本浏览器中不支持 Proxy 时,如何实现响应式系统。
Proxy
类似于 vue2 响应式原理 的做法,使用 Object.defineProperty 来模拟 Proxy 的功能,但存在局限性,无法监听:
Object.defineProperty
因此,跟 Vue 2 一样,我们需要提供必要的方法来新增监听,这里暂时命名为 createReactive。
createReactive
约束如下:
push
splice
shift
class CustomElement extends HTMLElement { data = { a: 'a' }; handle() { setReactive(this.data, 'b', 'b'); // this.data.b = 'b'; } }
提供一个入口,当用户修改属性后,主动调用,发起更新。入口有两个方案:
class CustomElement extends HTMLElement { data = { a: 'a' }; handle() { this.data.a = [ 1, 2, 3]; this.data.a[0] = -1; // 1. 在 class 上新增 forceUpdate ,不符合标准 this.forceUpdate(); // 2. 增加一个函数,入参为组件 forceUpdate(this); } }
The text was updated successfully, but these errors were encountered:
this.pwcForceUpdate + 1
this.pwcForceUpdate
Sorry, something went wrong.
No branches or pull requests
问题描述
当前 issue 主要是讨论在低版本浏览器中不支持
Proxy
时,如何实现响应式系统。方案一
类似于 vue2 响应式原理 的做法,使用
Object.defineProperty
来模拟Proxy
的功能,但存在局限性,无法监听:因此,跟 Vue 2 一样,我们需要提供必要的方法来新增监听,这里暂时命名为
createReactive
。约束如下:
push
,splice
,shift
等 Array 的方法对数组进行修改;createReactive
方法手动添加,例如:方案二
提供一个入口,当用户修改属性后,主动调用,发起更新。入口有两个方案:
The text was updated successfully, but these errors were encountered: