AngeloC
AngeloC

Reputation: 3533

How to capture native event in vuejs compoent

Here is a very simple Vuejs component which attempts to capture the click event of a span:

nativeOn: {
    click: function (event) {
        alert('clicked')
    }
},

… and here's the demo, but it does not work, what I'm missing here?

Upvotes: 1

Views: 1185

Answers (1)

Saurabh
Saurabh

Reputation: 73649

As you are registering the event on span element, you have to use on option as follows:

Vue.component('hello', {
  render: function(createElement) {
    return createElement("span", {
      on: {
        click: function(event) {
          alert('clicked')
        }
      },    
    }, "Hello ")
  }
})

see a live demo on jsfiddle.

Upvotes: 4

Related Questions