methods component vue code example
Example 1: vue methods
<template>
<div id="example">
<button v-on:click="greet">Greet</button>
</div>
</template>
<script>
export default {
methods: {
greet: function(event) {
alert(event.target.tagName);
}
}
};
</script>
Example 2: methods vue class component
<template>
<button v-on:click="hello">Click</button>
</template>
<script>
import Vue from 'vue'
import Component from 'vue-class-component'
@Component
export default class HelloWorld extends Vue {
hello() {
console.log('Hello World!')
}
}
</script>