移除后触发组件根元素上的原生事件有变化!
Vue2
加上 事件修饰符.native
,即可触发原生事件。
<!-- 父组件中使用 -->
<my-component @mouseover.native="onMouseover" />
Vue3
移除 事件修饰符 .native,默认可触发原生事件。
<!-- 父组件中使用 -->
<my-component @mouseover="onMouseover" />
但有如下两种情况无效;
-
子组件设置
emit
选项 ;<!-- 子组件 MyComponent --> <script> export default { emits: ['mouseover'] } </script>
-
子组件设置
inheritAttrs: false
;<!-- 子组件 MyComponent --> <script> export default { inheritAttrs: false, } </script>