vue --- 2.0 编译的实现
生活随笔
收集整理的這篇文章主要介紹了
vue --- 2.0 编译的实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
初識
- 假設html中有如下dom:
編譯
- Lz類如下:
- Compile類
compile函數的實現
compile(el) {const childNodes = el.childNodes;Array.from(childNodes).forEach(node => {// 類型判斷if (this.isElement(node)) {// 元素// console.log('編譯元素' + node.nodeName);// 查找 k-, @, :const nodeAttrs = node.attributes;Array.from(nodeAttrs).forEach(attr => {const attrName = attr.name; // 屬性名const exp = attr.value; // 屬性值if (this.isDirective(attrName)) {// l-textconst dir = attrName.substring(2); // 拿出text// 執行指令this[dir] && this[dir](node, this.$vm, exp);}if (this.isEvent(attrName)) {}})} else if (this.isInterpolation(node)) {// 文本this.compileText(node);}// 遞歸子節點if (node.childNodes && node.childNodes.length > 0) {this.compile(node);}}) } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的vue --- 2.0 编译的实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查看.npy文件
- 下一篇: echarts 生成 迁徙图_echar