当然是最难的一部分了,就是我们的编译模板。...拿到我们需要的 DOM 元素
然后需要解析 {{}} 模板插值
解析 m-text 指令
解析 m-html 指令
所以我们需要一个编译模板 Compile 类:
class Compile {
constructor...:
update(node, key, dir) {
const fn = this[dir+'Updater']; // 查找指令方法
fn && fn(node, this....node, key) {
this.update(node, key, 'text')
}
如果是 html 内容就只更新 htm 内容:
htmlUpdater(node, val) {
node.innerHTML...= val
}
html(node, key) {
this.update(node, key, 'html');
}
模板插值解析:
compileText(node) {
this.update