qieguo2016 / vueuv Goto Github PK
View Code? Open in Web Editor NEW参照Vue实现的一个JavaScript MVVM 框架,手把手教你从零开始Make Your Own Vue!
Home Page: https://qieguo2016.github.io/Vueuv/examples/todoMVC/index.html
License: MIT License
参照Vue实现的一个JavaScript MVVM 框架,手把手教你从零开始Make Your Own Vue!
Home Page: https://qieguo2016.github.io/Vueuv/examples/todoMVC/index.html
License: MIT License
computed里面的属性放啊 不应该有set方法
src/Vueuv.js 59行 应该提示 用户 computed里面的属性方法不能set
set : function (newVal) {
if (val === newVal) {
return;
}
val = newVal; // setter本身已经做了赋值,val作为一个闭包变量,保存最新值
if (Array.isArray(newVal)) {
self.observeArray(newVal, dep); // 递归监视,数组的监视要分开
} else {
self.observe(newVal); // 递归对象属性到基本类型为止
}
dep.notify(); // 触发通知
}
假如一开始data = { num: 3}
,后面赋值data.num = 2
,2
是以传值的方式赋给newVal
的,这个时候监视newVal
,而data.num = 2
指的是另外一个内存,虽然data.num
的值也是2
,我的意思就是这里存在两块内存,而现在监视的是newVal那块内存,data.num是怎么监视成功的?
对data里面的a,b都修改了值,会触发deps数组里面的这两个的cb函数。而cb函数最终是要操作DOM的。如果加上虚拟DOM,会先修改虚拟DOM,然后再操作DOM。那岂不是需要执行两次DOM更新?
Observer.prototype.defineReactive方法中的Object.defineProperty方法中
if (Array.isArray(val)) {
self.observeArray(val, dep); // 递归监视,数组的监视要分开
} else {
self.observe(val); // 递归对象属性到基本类型为止
}
这个几行代码和外面的重复
if (Array.isArray(newVal)) {
self.observeArray(newVal, dep); // 递归监视,数组的监视要分开
} else {
self.observe(newVal); // 递归对象属性到基本类型为止
}
这里为何要重复监视?不懂
大佬关于ast也写一篇文章呗
觉得你的解释通俗易懂,非常赞👍
// if/for懒编译(编译完其他指令后才编译)
if (lazyCompileExp) {
this[lazyCompileDir + 'Handler'](node, scope, lazyCompileExp);
} else {
this.compile(node, scope);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.