In Vue, why can you assign a listener both with ()
and without ()
?
new Vue({
el: "#app",
data: {
userName: "Hello World!"
},
methods: {
changeName: function(e){
this.userName = "Name "+Math.random();
}
}
})
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<div id="app">
<p> {{ userName }} </p>
<!-- typing in both the input fields trigger changeName -->
<input @input="changeName()">
<input @input="changeName">
</div>
In the above code snippet, input event on both the input fields trigger changeName
nicely in spite one has parentheses around it ()
and one doesn't.