查看“Vue 事件修饰符”的源代码
←
Vue 事件修饰符
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
https://www.bilibili.com/video/BV1Zy4y1K7SH?p=15 事件冒泡:html 中,节点和它的父节点绑定了相同的事件处理函数,当触发事件时会触发两次。 当点击发生,先经过的阶段是事件捕获,随后才是事件冒泡,默认情况下,事件冒泡阶段才是去处理事件的。 捕获阶段是由外往内(由父元素到子元素)的,随后再触发的是冒泡阶段,冒泡阶段是由内往外(子元素到父元素)的。<syntaxhighlight lang="html"> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>事件修饰符</title> <script type="text/javascript" src="../js/vue.js"></script> <style> * { margin-top: 20px; } .demo1{ height: 50px; background-color: skyblue; } .box1{ padding: 5px; background-color: skyblue; } .box2{ padding: 5px; background-color: orange; } .list{ width: 200px; height: 200px; background-color: peru; overflow: auto; } li { height: 100px; } </style> </head> <body> <!-- Vue 中的事件修饰符: 1.prevent:阻止默认事件(常用); 2.stop:阻止事件冒泡(常用); 3.once:事件只触发一次(常用) 4.capture:使用事件的捕获模式; 5.self:只有 event.target 是当前操作的元素时才出发事件; 6.passive:事件的默认行为立即执行,无需等待时间回调执行完毕; --> <div id="root"> <h2>欢迎来到{{name}}</h2> <!-- 阻止默认事件(常用) --> <a href="http://www.bing.com/" @click.prevent="showInfo">点我提示信息</a> <!-- 阻止事件冒泡(常用) --> <div class="demo1" @click="showInfo"> <button @click.stop="showInfo">点我提示信息</button> </div> <!-- 事件只触发一次(常用) --> <button @click.once="showInfo">点我提示信息</button> <!-- 使用事件的捕获模式 --> <div class="box1" @click.capture="showMsg(1)"> div1 <div class="box2" @click="showMsg(2)"> div2 </div> </div> <!-- 只有 event.target 是当前操作的元素时才出发事件 --> <div class="demo1" @click.self="showInfo"> <button @click="showInfo">点我提示信息</button> </div> <!-- 事件的默认行为立即执行,无需等待事件的回调执行完毕 --> <ul @scroll="demo" class="list"> <!-- <ul @wheel="demo" class="list"> --> <!-- <ul @wheel.passive="demo" class="list"> --> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </div> </body> <script type="text/javascript"> new Vue({ el:'#root', data:{ name:'北京' }, methods:{ showInfo(e){ //e.preventDefault(); //e.stopPropagation() // alert('hello'); console.log(e.target); }, showMsg(msg){ console.log(msg); }, demo(){ // console.log('@'); for (let index = 0; index < 100000; index++) { console.log('#'); } console.log('累坏了'); } } }) </script> </html> </syntaxhighlight>
返回至
Vue 事件修饰符
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
Spring Boot 2 零基础入门
Spring Cloud
Spring Boot
设计模式之禅
VUE
Vuex
Maven
算法
技能树
Wireshark
IntelliJ IDEA
ElasticSearch
VirtualBox
软考
正则表达式
程序员精讲
软件设计师精讲
初级程序员 历年真题
C
SQL
Java
FFmpeg
Redis
Kafka
MySQL
Spring
Docker
JMeter
Apache
Linux
Windows
Git
ZooKeeper
设计模式
Python
MyBatis
软件
数学
PHP
IntelliJ IDEA
CS基础知识
网络
项目
未分类
MediaWiki
镜像
问题
健身
国债
英语
烹饪
常见术语
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息