Skip to content

Instantly share code, notes, and snippets.

@YiqinZhao
Created March 9, 2018 07:03
Show Gist options
  • Save YiqinZhao/d46e436d3ade1d0adfd4eb4959b82140 to your computer and use it in GitHub Desktop.
Save YiqinZhao/d46e436d3ade1d0adfd4eb4959b82140 to your computer and use it in GitHub Desktop.
[Vue Reactive Data] How to implement a Vue styled reactive data.
// 元数据
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