Skip to content

Commit

Permalink
polish: add warning when .native modifier is used on native HTML elem…
Browse files Browse the repository at this point in the history
…ents (#9884)
  • Loading branch information
NataliaTepluhina authored and yyx990803 committed Apr 25, 2019
1 parent bd6cea0 commit 861aea1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/vdom/create-element.js
Expand Up @@ -98,6 +98,12 @@ export function _createElement (
ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag)
if (config.isReservedTag(tag)) {
// platform built-in elements
if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.nativeOn)) {
warn(
`The .native modifier for v-on is only valid on components but it was used on <${tag}>.`,
context
)
}
vnode = new VNode(
config.parsePlatformTagName(tag), data, children,
undefined, undefined, context
Expand Down
14 changes: 14 additions & 0 deletions test/unit/features/directives/on.spec.js
Expand Up @@ -460,6 +460,20 @@ describe('Directive v-on', () => {
expect(spy).toHaveBeenCalled()
})

it('should throw a warning if native modifier is used on native HTML element', () => {
vm = new Vue({
el,
template: `
<button @click.native="foo"></button>
`,
methods: { foo: spy },
})

triggerEvent(vm.$el, 'click')
expect(`The .native modifier for v-on is only valid on components but it was used on <button>.`).toHaveBeenWarned()
expect(spy.calls.count()).toBe(0)
})

it('.once modifier should work with child components', () => {
vm = new Vue({
el,
Expand Down

0 comments on commit 861aea1

Please sign in to comment.