Comparing methods, watchers, and computed properties
Methods are best used as a handler to an event occurring in the DOM, and in situations where you need to call a function or perform an API call, for example, Date.now(). All values returned by methods are not cached.
For example, you can compose an action denoted by @click, and reference a method:
<template>
<button @click="getDate">Click me</button>
</template>
<script>
export default {
methods: {
getDate() {
alert(Date.now())
}
}
}
</script>
This code block will display an alert bar with the current Unix epoch time whenever a user clicks on the Click me button. Methods should not be used to display computed data, since the return value of...