Vue基础语法-事件监听

tech2025-09-07  7

事件监听

v-on指令v-on指令的简写方式直接写@ <div id="app"> <h2>{{count}}</h2> <button v-on:click="addCount"></button><br> <!-- v-on的简写方法 --> <button @click="addCount"></button><br> <input type="text" v-on:focus="alertMsg"/> </div> <script type="text/javascript"> var app=new Vue({ el:"#app", data:{ count:0 }, methods:{ addCount(){ this.count++ }, alertMsg(){ alert("msg..."); } } }) </script>
最新回复(0)