Created
March 9, 2018 07:03
-
-
Save YiqinZhao/d46e436d3ade1d0adfd4eb4959b82140 to your computer and use it in GitHub Desktop.
[Vue Reactive Data] How to implement a Vue styled reactive data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 元数据 | |
let a = { | |
source: { number: 0 } | |
} | |
// 核心:Object.defineProperty | |
Object.defineProperty(a, 'number', { | |
enumerable: true, | |
configurable: true, | |
get: function () { | |
return this.source.number | |
}, | |
set: function (val) { | |
console.log(this.source.number, '-->', val); | |
this.source.number = val | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment