Skip to content
New issue

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

能否加入对数组观察的支持 #4

Open
undefined27 opened this issue Apr 21, 2017 · 5 comments
Open

能否加入对数组观察的支持 #4

undefined27 opened this issue Apr 21, 2017 · 5 comments

Comments

@undefined27
Copy link

No description provided.

@amorist
Copy link

amorist commented May 16, 2018

他明确说明只是简版的实现,想改良,可以去参考下vue,人家只是讲了下原理

@bowencool
Copy link

bowencool commented Jan 18, 2019

我自己翻版了一个,支持观察数组,希望能帮到你
https://github.com/bowencool/bue

@poyiding
Copy link

Vue 2.x 通过 Object.defineProperty 来劫持是不支持数组的,你可以用 es6 proxy 来实现对数组的观察,实际上,Vue 3.0 也是通过 proxy 来实现。具体你可以查 proxy 双向绑定。

@echofly
Copy link

echofly commented Feb 13, 2019

No description provided.

@ckvv
Copy link

ckvv commented Nov 2, 2019

Object.defineProperty

Vue 2.x 通过 Object.defineProperty 来劫持是不支持数组的,你可以用 es6 proxy 来实现对数组的观察,实际上,Vue 3.0 也是通过 proxy 来实现。具体你可以查 proxy 双向绑定。

arr.forEach(function(val,index) {
        Object.defineProperty(data, index, {
            enumerable: true, // 可枚举
            configurable: false, // 不能再define
            get: function() {
                return val;
            },
            set: function(newVal) {
                console.log('哈哈哈,监听到值变化了 ', val, ' --> ', newVal);
                val = newVal;
            }
        });
	});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants