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
No description provided.
The text was updated successfully, but these errors were encountered:
Vue 在 3.0 版本对数据响应式做了重构,从原先 Vue2.x 的 Object.defineproperty 转换为 Proxy 对象代理。
Object.defineproperty
Proxy
为什么要替换成 Proxy 呢?
Object.definproperty是通过属性监听对象的,如果对象上有多个属性时就得遍历多个属性达到监听的效果,那这样就有一个问题,如果监听对象层级比较深时我们一开始就得递归遍历内层对象,如果我们的数据量大会对性能有一定的负担。
Object.definproperty
同时如果我们对对象进行增加或删除属性时 Object.definproperty 并不会监听并做对应的拦截处理,为了才会有 Vue.$set 来解决这个问题,同样如果监听的是一个数组,对数组动态进行增删操作也不会被监听到,(Vue 中之所以可以监听到是因为他对数组的方法进行了劫持,在你调用对应的Api时会进行监听操作);
上面说的都是 Object.definproperty 的坏话,但是其实在 Proxy 没有出来前他是唯一监听数据的方法,那么 Proxy 究竟有什么优点呢?
Proxy 是直接对对象监听,它会返回一个新的对象,我们对这个对象的操作都可以被监听到,Proxy 的优点在于
has()
get()
set()
ownKeys()
不过它个缺点,就是兼容性太差。
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: