Please see this minimum example:
<template>
<div>
<!-- I understand that this works -->
<button @click="click">Click</button>
<!-- Why is this working? Does Vue has some kind of auto detection? -->
<!-- If so, how does Vue detect it? -->
<button @click="click()">Click</button>
</div>
</template>
<script>
export default {
methods: {
click() {
alert("Clicked!");
}
}
};
</script>
As you can see, I have a click method that simply alert something, and I have two different way to bind the method in template, why is this happening?
How does Vue resolve @click="click()"
under the hood? Why does this not immediately invoke click
method once?