27
loading...
This website collects cookies to deliver better user experience
<div id="app">
<!-- `sayHello` is the name of a method -->
<button v-on:click="sayHello">Hi</button>
</div>
var example2 = new Vue({
el: '#app',
data: {
name: 'Vue.js'
},
// define methods under the `methods` object
methods: {
sayHello: function (event) {
// `this` inside methods points to the Vue instance
alert('Hello ' + this.name + '!')
// `event` is the native DOM event
if (event) {
//this will show the tag which fired the event
alert(event.target.tagName)
}
}
}
})
// you can invoke methods in JavaScript too
example2.greet() // => 'Hello Vue.js!'
<div id="app">
<button v-on:dblclick="handleDoubleClick">Pssst. Double click me ;)</button>
</div>
var app = new Vue({
el: '#app',
methods : {
handleDoubleClick : function() {
console.log("Hi, here we are dealing with a double click it seems....");
}
}
})
<button v-on:click="handleEvent($event)">We'll do it the old way</button>