<svg class="sketch" @mousemove="moveComponent" @mouseup="removeComponent" @mousedown="chooseComponent" @mouseover="displayTool"
上述函数中都要触发某段相同代码A,所以才想是否能将此段代码A绑定到所有Mouse事件。
暂时这样用,请教更好的方案/现成的API
addEventListener(['mousemove', 'mouseup', 'mousedown'], this.$el, this.triggerWatch);
export function addEventListener(events, el, func) {
events.forEach(function(event) {
el.addEventListener(event, func, false);
});
}
1、在所有的mouse事件中都执行代码A
2、所有mouse事件执行同一函数包含代码A,然后在这个函数中根据mouse事件的类型去调用不同的函数
3、...