> v-on 指令用于監(jiān)聽 DOM 事件 #### 1. v-on 基本使用 --- ```html <div id="app"> <button v-on:click="test">測(cè)試</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">測(cè)試</button> <button @click="test">測(cè)試</button> ``` #### 2. 修飾符 --- ```html <div id="app"> <span v-on:click="go2('222')"> <!-- .stop 阻止冒泡 --> <span v-on:click.stop="go('111')">點(diǎn)我</span> </span> <br> <!-- 只有第一次點(diǎn)擊會(huì)觸發(fā)函數(shù) --> <span v-on:click.once="go(333)">只觸發(fā)一次</span> </div> ``` **方法中的 `this` 自動(dòng)綁定為當(dāng)前 `Vue實(shí)例`** ```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> ```