(
el, //虚拟dom
name, //name 事件名称 事件类型
value, //事件函数
modifiers, //事件类型状态状态
important, // 根据important为true 把事件添加在前面 假就添加在尾部
warn //警告日志
)
| 9707 | //为虚拟dom添加events 事件对象属性,如果添加@click='clickEvent' 则此时 虚拟dom为el.events.click.value="clickEvent" |
| 9708 | //或者虚拟dom添加nativeEvents 事件对象属性,如果添加@click.native='clickEvent' 则此时 虚拟dom为el.nativeEvents.click.value="clickEvent" |
| 9709 | function addHandler( |
| 9710 | el, //虚拟dom |
| 9711 | name, //name 事件名称 事件类型 |
| 9712 | value, //事件函数 |
| 9713 | modifiers, //事件类型状态状态 |
| 9714 | important, // 根据important为true 把事件添加在前面 假就添加在尾部 |
| 9715 | warn //警告日志 |
| 9716 | ) { |
| 9717 | |
| 9718 | modifiers = modifiers || emptyObject; |
| 9719 | // warn prevent and passive modifier |
| 9720 | /* istanbul ignore if */ |
| 9721 | if ( |
| 9722 | "development" !== 'production' && warn && |
| 9723 | modifiers.prevent && modifiers.passive |
| 9724 | ) { |
| 9725 | warn( |
| 9726 | 'passive and prevent can\'t be used together. ' + |
| 9727 | 'Passive handler can\'t prevent default event.' |
| 9728 | ); |
| 9729 | } |
| 9730 | |
| 9731 | // check capture modifier 检查捕获修饰符 |
| 9732 | if (modifiers.capture) { |
| 9733 | delete modifiers.capture; |
| 9734 | name = '!' + name; // mark the event as captured 将事件标记为捕获 |
| 9735 | } |
| 9736 | if (modifiers.once) { //将事件标记为一次 |
| 9737 | delete modifiers.once; |
| 9738 | name = '~' + name; // mark the event as once 将事件标记为一次 |
| 9739 | } |
| 9740 | /* istanbul ignore if */ |
| 9741 | if (modifiers.passive) { |
| 9742 | delete modifiers.passive; |
| 9743 | name = '&' + name; // mark the event as passive 将事件标记为被动的 |
| 9744 | } |
| 9745 | |
| 9746 | // normalize click.right and click.middle since they don't actually fire |
| 9747 | // this is technically browser-specific, but at least for now browsers are |
| 9748 | // the only target envs that have right/middle clicks. |
| 9749 | //点击正常化。并点击。中间,因为它们实际上不会开火 |
| 9750 | //这在技术上是特定于浏览器的,但至少现在浏览器是 |
| 9751 | //唯一有右/中点击的目标环境。 |
| 9752 | if (name === 'click') {//判断是否是点击事件 |
| 9753 | if (modifiers.right) { //判断是否是鼠标右击 |
| 9754 | name = 'contextmenu'; |
| 9755 | delete modifiers.right; |
| 9756 | } else if (modifiers.middle) {//如果是鼠标左击 |
| 9757 | name = 'mouseup'; //变成鼠标抬起事件 |
| 9758 | } |
| 9759 | } |
| 9760 | |
| 9761 | var events; |
| 9762 | if (modifiers.native) { // 判断是有原生事件修饰符 通俗点讲:就是在父组件中给子组件绑定一个原生的事件,就将子组件变成了普通的HTML标签,不加'. native'事件是无法触 发的。 |
| 9763 | /* |
| 9764 | * 比如<my-component @click="outClick"></my-component> 这样是不会触发事件的 |
| 9765 | * 需要加修饰符<my-component @click.native="outClick"></my-component> 这样是不会触发事件的 |
| 9766 | * */ |
no outgoing calls
no test coverage detected