Skip to content

Instantly share code, notes, and snippets.

@earth774
Last active March 18, 2019 04:55
Show Gist options
  • Save earth774/9c03c017421d70d961f71a23546592b3 to your computer and use it in GitHub Desktop.
Save earth774/9c03c017421d70d961f71a23546592b3 to your computer and use it in GitHub Desktop.
event handler vue
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Amiearth</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="example-2">
<!-- `greet` is the name of a method defined below -->
<button v-on:click="greet()">Greet</button>
</div>
<script>
var example2 = new Vue({
el: '#example-2',
data: {
name: 'Vue.js'
},
// define methods under the `methods` object
methods: {
greet: function () {
// `this` inside methods points to the Vue instance
alert('Hello ' + this.name + '!')
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment