Vue源码分析之模板解析
模板解析 基本流程 1、将el的所有子节点取出,添加到一个新建的文档fragment对象中 function MVVM (options) { this.$options = options var data = this._data = this.$options.data var me = this // 创建一个编译对象 this.$compile = new Compile(options.el || document.body, this) } function Compile (el, vm) { this.$vm = vm this.$el = this.isElement(el) ? el : document.querySelector(el) if (this.$el) { this.$fragment = this.node2fragment(this.$el) //取出el元素中所有的子节点保存到一个fragment对象中 this.init() this.$el.appendChild(this.$fragment) } } Compile.prototype = { node2fragment: function (el) { var fragment = document.createDocumentFragment(), child = this