Code Monkey home page Code Monkey logo

self-vue's Issues

无法监测 vm.data中 类型为Object的属性变化

eg.

        el: '#app',
        data: {
            title: 'hello world',
			name: 'canfoo',
			obj: {
				c: 3
			}
        },

此处 如果执行 obj.c = 4 , 不会被监听,因为我看到 watcher.js中 这段逻辑

        var value = this.vm.data[this.exp];
        var oldVal = this.value;
        if (value !== oldVal) {

引用类型 , 不会进入此if判断。

****************************************分割线***************************************

问题2: 并且 compile.js无法编译 这样的东西 <h1>obj c: {{obj.c}}</h1>

有几个问题想问下

1、 var dep = new Dep(); 这是消息订阅器放订阅者的集合容器,为什么要写在 defineReactive里面 这里递归后dep会被多次创建啊 难道dep不应该是只有一个消息订阅器吗?

2、 dep.notify(); 这里为什么要通知全部订阅者啊? 不应该是只通知与该数据字段变化所对应绑定的订阅者吗?
function defineReactive(data, key, val) {
observe(val); // 递归遍历所有子属性
var dep = new Dep();
Object.defineProperty(data, key, {
enumerable: true,
configurable: true,
get: function() {
if (Dep.target) {. // 判断是否需要添加订阅者
dep.addSub(Dep.target); // 在这里添加一个订阅者
}
return val;
},
set: function(newVal) {
dep.notify(); // 如果数据变化,通知所有订阅者
}
});
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.