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/[email protected]/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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…