> v-on 指令用于監(jiān)聽 DOM 事件 #### 1. v-on 基本使用 --- ```html <div id="app"> <button v-on:click="test">測試</button> </div> ``` ```javascript <script> let vm = new Vue({ el: '#app', methods: { test: function() { console.log(123) }, } }) </script> ``` **`v-on` 可縮寫為 `@`** ```html <button v-on:click="test">測試</button> <button @click="test">測試</button> ``` #### 2. 修飾符 --- ```html <div id="app"> <span v-on:click="go2('222')"> <!-- .stop 阻止冒泡 --> <span v-on:click.stop="go('111')">點我</span> </span> <br> <!-- 只有第一次點擊會觸發(fā)函數(shù) --> <span v-on:click.once="go(333)">只觸發(fā)一次</span> </div> ``` **方法中的 `this` 自動綁定為當前 `Vue實例`** ```javascript <script> let vm = new Vue({ el: '#app', methods: { test: function() { console.log(123) }, go: function(msg) { console.log(msg, this) }, go2: function(msg) { console.log(msg, this) }, } }) </script> ```