vue3双向绑定原理

区别

Vue.prototype.Observer = function (data) {
    const that = this;
    for (var key in data) {
        that.deps[key] = []; //初始化所有订阅者对象{msg: [订阅者], info: []}
    }
    let handler = {
        get(target, property) {
            return target[property];
        },
        set(target, key, value) {
            let res = Reflect.set(target, key, value);
            var watchers = that.deps[key];
            watchers.map(item => {
                item.update();
            });
            return res;
        }
    }
    this.$data = new Proxy(data, handler);
}

你可能感兴趣的:(vue3双向绑定原理)