undefinedfix
Sign in

How to realize bidirectional binding of Vue data?

zwjix edited in Sat, 03 Sep 2022

Data of object type is generated through object . Defineproperty to monitor link descriptions. What about other types? Like string or number

4 Replies
nnohj
commented on Sat, 03 Sep 2022

As explained in the article you connected, an observer will be implemented to hijack the data value of Vue, and the data value of Vue can be of any data type

walk: function(data) {
        var self = this;
        //这里是通过对一个对象进行遍历,对这个对象的所有属性都进行监听
        Object.keys(data).forEach(function(key) {
            self.defineReactive(data, key, data[key]);
        });
    },

Note: This is to traverse an object and listen to all the properties of the object. The object here refers to data in Vue

Ra777
commented on Sat, 03 Sep 2022

Your different data types are all in the object

clipboard.png

Reference blog: https://blog.csdn.net/qq_ 4285...

mmeisner
commented on Sun, 04 Sep 2022

No matter what type it is, it's in the data object

Tirafesi
commented on Sun, 04 Sep 2022

The data of walk is not the data of Vue. The data of Vue is state.js#L151 In the middle. Recursion occurs if data is object / array. core/instance/ state.js#L151core/observer/index .js#L156

lock This question has been locked and the reply function has been disabled.