前端学习(1190):事件修饰符
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1190):事件修饰符
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳統方式
<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!-- v-cloak用法 --><style>[v-cloak] {display: none;}/* 先通過樣式隱藏內容 然后在內存中替換 然后再顯示想要的結果 */</style> </head> <!-- v-once顯示的信息不需要后期修改 這樣可以提高性能 --><body><div id="app"><div>{{num}}</div><div v-on:click='handle0'><button @click='handle1'>點擊2</button><!-- <button @click='handle2(123,456,$event)'>點擊3</button> --></div></div><!-- 刷新的時候有閃動 --><script type="text/javascript" src="./js/vue.js"></script><script>/* VUE基本使用 *//* 填充數據 *//* 引入js *//* 語法功能 */var vm = new Vue({//綁定的標簽el: '#app',//數據顯示data: {//msg: 'Hello Vue',num: 0/* info: '你好' */},methods: {/* handle2: function(p, p1, event) {console.log(p, p1);console.log(event.target.tagName);this.num++;}, */handle0: function() {this.num++;},handle1: function(event) {//阻止冒泡event.stopPropagation();// console.log(event.target.innerHTML);}}});</script> </body></html>vue
<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!-- v-cloak用法 --><style>[v-cloak] {display: none;}/* 先通過樣式隱藏內容 然后在內存中替換 然后再顯示想要的結果 */</style> </head> <!-- v-once顯示的信息不需要后期修改 這樣可以提高性能 --><body><div id="app"><div>{{num}}</div><div v-on:click='handle0'><!-- 阻止冒泡 --><button @click.stop='handle1'>點擊2</button><!-- <button @click='handle2(123,456,$event)'>點擊3</button> --></div><div><a href="http://www.baidu.com" v-on:click.prevent='handle2'>點擊</a></div></div><!-- 刷新的時候有閃動 --><script type="text/javascript" src="./js/vue.js"></script><script>/* VUE基本使用 *//* 填充數據 *//* 引入js *//* 語法功能 */var vm = new Vue({//綁定的標簽el: '#app',//數據顯示data: {//msg: 'Hello Vue',num: 0/* info: '你好' */},methods: {/* handle2: function(p, p1, event) {console.log(p, p1);console.log(event.target.tagName);this.num++;}, */handle0: function() {this.num++;},handle1: function(event) {//阻止冒泡// event.stopPropagation();// console.log(event.target.innerHTML);},handle2: function(event) {event.preventDefault();}}});</script> </body></html>運行結果
總結
以上是生活随笔為你收集整理的前端学习(1190):事件修饰符的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端学习(1045):todolist本
- 下一篇: 前端学习(736):函数的返回值retu