MCPcopy Create free account
hub / github.com/ygs-code/vue / stateMixin

Function stateMixin

vue.js:5222–5299  ·  view source on GitHub ↗
(Vue)

Source from the content-addressed store, hash-verified

5220
5221 //数据绑定,$watch方法
5222 function stateMixin(Vue) {
5223 // flow somehow has problems with directly declared definition object
5224 //流在某种程度上与直接声明的定义对象有问题
5225 // when using Object.defineProperty, so we have to procedurally build up
5226 //在使用Object.defineProperty时,我们必须循序渐进地进行构建
5227 // the object here. 这里的对象。
5228 var dataDef = {};
5229 //重新定义get 和set方法
5230 dataDef.get = function () {
5231 return this._data //获取data中的数据
5232 };
5233
5234 var propsDef = {};
5235 propsDef.get = function () {
5236 return this._props// 获取props 数据
5237 };
5238
5239 {
5240 dataDef.set = function (newData) {
5241 //避免替换实例根$data。 使用嵌套数据属性代替
5242 warn(
5243 'Avoid replacing instance root $data. ' +
5244 'Use nested data properties instead.',
5245 this
5246 );
5247 };
5248 propsDef.set = function () {
5249 //props 只是可度的数据不可以设置更改
5250 warn("$props is readonly.", this);
5251 };
5252 }
5253 console.log('==dataDef==')
5254 console.log(dataDef)
5255
5256
5257 Object.defineProperty(Vue.prototype, '$data', dataDef);
5258 Object.defineProperty(Vue.prototype, '$props', propsDef);
5259
5260 //添加多一个数组数据或者对象数据
5261 Vue.prototype.$set = set;
5262 //删除一个数组数据或者对象数据
5263 Vue.prototype.$delete = del;
5264
5265 Vue.prototype.$watch = function (expOrFn, //用户手动监听
5266 cb, // 监听 变化之后 回调函数
5267 options //参数
5268 ) {
5269 var vm = this;
5270 if (isPlainObject(cb)) { //判断是否是对象 如果是对象则递归 深层 监听 直到它不是一个对象的时候才会跳出递归
5271 // 转义handler 并且为数据 创建 Watcher 观察者
5272 return createWatcher(
5273 vm,
5274 expOrFn,
5275 cb,
5276 options
5277 )
5278 }
5279 options = options || {};

Callers 1

vue.jsFile · 0.85

Calls 2

isPlainObjectFunction · 0.85
createWatcherFunction · 0.85

Tested by

no test coverage detected