Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

interfacekun/ccc-vue

Repository files navigation

借鉴vue实现的观察者

参考了vue的源码:https://github.com/vuejs/vue

使用

import Vue from './Vue';
import Watcher from './Watcher';
function bindCallback(newValue, oldValue) {
 console.log('bindCallback', newValue, oldeValue);
}
// 观察的数据
let data = {
 test: "123";
}
// 观察
let vm = new Vue(data);
// 订阅data.test的变化,当data.test的值变化的时候触发 bindCallback;
let watcher = Vue.bind(new Watcher(vm, bindCallback, this), data.test);
// or let watcher = Vue.bind(new Watcher(vm, bindCallback, this), vm.test)
// 修改data.test的值,触发bindCallback
vm.test = "456";
// 取消订阅,data.test值再变化的时候不再触发回调
watcher.teardown()
// 修改data.test的值,但不再触发回调
vm.test = "789";

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /