今天来实现一个简易版的Vue2.0响应式
class Vue {
constructor(options) {
this.$options = options
this.$data = options.data
// 重写数组方法
let arrayPrototype = Array.prototype
const methods = ['pop', 'push', 'shift', 'unshift']
this.proto = Object.create(arrayPrototype)
methods.forEach(method => {
this.proto[method] = function() {
arrayPrototype[method].call(this, ...arguments)
}
})
// 响应化
this.observe(this.$data)
// 测试代码
// new Watcher(this, 'test')
// this.test
// 创建编译器