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

【vue】getter,setter原理 #25

Open
Kelichao opened this issue Mar 22, 2017 · 0 comments
Open

【vue】getter,setter原理 #25

Kelichao opened this issue Mar 22, 2017 · 0 comments

Comments

@Kelichao
Copy link
Owner

Kelichao commented Mar 22, 2017

Vue原理

  • 通过Object.defineProperty方法,但此方法不适用于IE8及以下浏览器

default

var person = {
    name: "Bob"
};

Object.defineProperty(person, "name", {
    // 是否可以从对象中删除
    configurable: true,
    get: function() {
        console.log("触发了get方法");
    },
    set: function() {
        console.log("触发了set方法");
    }
})

注意点

  • 响应式中某个数据为数组的引用类型时,需要改变其整个数据源才能动态刷新数值。
// 比如某数据源是一个数组
vue1.arr = [1,2,3] 

// 不会刷新页面显示
vue1.arr[0] = 0;

// 刷新页面
vue1.arr = [0,2,3]
@Kelichao Kelichao changed the title 【vue】原理 【vue】getter,setter原理 Mar 22, 2017
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

1 participant