此文记录myVue.js对于事件绑定的处理
/**
* 编译
* 对模板变量
*/
compile(node) {
node.childNodes.forEach((item, index) => {
//元素节点
if (item.nodeType === 1) {
//事件监听
if (item.hasAttribute("@click")) {
let vmKey = item.getAttribute("@click");
//做函数监听
if (Object.prototype.toString.call(this.$options.methods[vmKey]) === "[object Function]") {
item.addEventListener('click', (event) => {
this.$options.methods[vmKey].call(this, event);
});
};
};
//递归查看元素节点的子节点
this.compile(item);
}
})
};