Skip to content

Commit 861aea1

Browse files
NataliaTepluhinayyx990803
authored andcommitted
polish: add warning when .native modifier is used on native HTML elements (#9884)
1 parent bd6cea0 commit 861aea1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/core/vdom/create-element.js

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export function _createElement (
9898
ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag)
9999
if (config.isReservedTag(tag)) {
100100
// platform built-in elements
101+
if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.nativeOn)) {
102+
warn(
103+
`The .native modifier for v-on is only valid on components but it was used on <${tag}>.`,
104+
context
105+
)
106+
}
101107
vnode = new VNode(
102108
config.parsePlatformTagName(tag), data, children,
103109
undefined, undefined, context

test/unit/features/directives/on.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,20 @@ describe('Directive v-on', () => {
460460
expect(spy).toHaveBeenCalled()
461461
})
462462

463+
it('should throw a warning if native modifier is used on native HTML element', () => {
464+
vm = new Vue({
465+
el,
466+
template: `
467+
<button @click.native="foo"></button>
468+
`,
469+
methods: { foo: spy },
470+
})
471+
472+
triggerEvent(vm.$el, 'click')
473+
expect(`The .native modifier for v-on is only valid on components but it was used on <button>.`).toHaveBeenWarned()
474+
expect(spy.calls.count()).toBe(0)
475+
})
476+
463477
it('.once modifier should work with child components', () => {
464478
vm = new Vue({
465479
el,

0 commit comments

Comments
 (0)