事件处理 v-on
<!--事件的基本使用:1. 使用 v-on:xxx 或 @xxx 綁定事件,其中 xxx 是事件名2. 事件的回調(diào)需要配置在 methods 對象中,最終會在 vm 上3. methods 中配置的函數(shù),不要用箭頭函數(shù)!否則 this 就不是 vm 了4. methods 中配置的函數(shù),都是被 Vue 所管理的函數(shù),this 的指向是 vm 或 組件實例對象5. @click="demo" 和 @click="demo($event)" 效果一致,但后者可以傳參
-->
<div id="root"><p><button v-on:click="showInfo">按鈕</button><button v-on:click="showInfo2($event, 1000)">按鈕</button></p>
</div>
<script src="../js/vue.js"></script>
<script>Vue.config.productionTip = false;const vm = new Vue({el: '#root',data: {name: 'mary',age: 18},methods: {showInfo(event) {console.log(event.target.innerText);},showInfo2(event, a) {console.log(event, a); // a:1000}}});
</script>
總結(jié)
- 上一篇: java 复制字段_java - 在构造
- 下一篇: USB虚拟串口