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
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

commented on Sat, 03 Sep 2022

Your different data types are all in the object


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

commented on Sun, 04 Sep 2022

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

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.