当前位置:网站首页>8. Event handling - event modifier
8. Event handling - event modifier
2022-07-20 08:40:00 【Where the wind falls】
1. The basic use of events
1. Use v-on:xxx perhaps @xxx The binding event , among xxx Is the event name
2. Event callback needs to be configured in methods in , Eventually it will be vm On
3.methods Functions configured in , Don't use arrow functions , otherwise this It's not vm 了
4.methods Functions configured in , It's all about being Vue Managed functions ,this The direction is vm Or component instance object
[email protected]="demo" and @click="demo($event)" The effect is consistent , But the latter can be passed on
2. Event modifier
1.prevent: Block default events
2.stop: Stop the event from bubbling ( Commonly used )
3.once: The event is triggered only once ( Commonly used )
4.capture: Use the capture mode for events ;
5.self: Only event.target Is the element of the current operation
6.passive: The default behavior of the event executes immediately , There is no need to wait for the event callback to complete
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/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>
<div id="root">
<h2> Welcome to {
{name}} Study </h2>
<!-- Block default events -->
<a href="http://www.atguigu.com" @click.prevent="showInfo"> Click I block default events </a>
<!-- Stop the event from bubbling --- Commonly used -->
<div class="demo1" @click="showInfo">
<button @click.stop="showInfo"> I'll stop the bubble </button>
</div>
<!-- The event is triggered only once ( Commonly used ) -->
<button @click.once="showInfo"> Click I only trigger one event </button>
<!-- Use the capture mode for events -->
<div class="box1" @click.capture="showMsg(1)">
div1
<div class="box2" @click="showMsg(2)">
div2
</div>
</div>
<!-- The default behavior of the event executes immediately , There is no need to wait for the event callback to complete ; -->
<!-- When scrolling the mouse wheel, trigger the default behavior first, and then execute the event callback -->
<ul @wheel.passive="demo" class="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</body>
</html>
<script type="text/javascript">
Vue.config.productionTip = false // prevent vue Generate production prompts at startup
new Vue({
el: "#root",
data: {
name: " Silicon Valley "
},
methods: {
showInfo(e) {
alert(" Hello, classmate der!")
console.log(e)
},
showMsg(msg){
console.log(msg)
},
demo(){
for (let i = 0; i < 100000; i++) {
console.log('#')
}
console.log(' The default behavior is executed immediately ')
}
}
})
</script>
边栏推荐
- Easier to use C language entry-level cheese (2) select statements + loop statements, functions, arrays, operators (super detailed)
- Explain the full permutation problem in detail (different output results of different solutions)
- Pytorch implements retinanet (III) definition and training of loss
- 【js】argument 介绍
- 4.MVC模型和MVVM模型
- 9.键盘事件
- 利用函数指针数组实现计算器编写
- 【学习笔记】“STL演讲比赛流程管理系统”作业总结
- 8.事件处理——事件修饰符
- The longest common subsequence of order 2 and order n
猜你喜欢
随机推荐
学习日记-指针专题
4000字,让你明白递推及其例题做法(C语言,有图)
指针数组和数组指针有什么区别?
Application of learning diary 5-c language function
Custom type: structure, bit segment, enumeration, union
巧解杨氏矩阵
利用函数指针数组实现计算器编写
C语言实现三子棋
My first blog
Easier to use C language entry-level cheese (1) data types, variables and constants, strings + escape characters + comments (super detailed)
Special topic of structure
Explain the full permutation problem in detail (different output results of different solutions)
Function recursion in C program
巩固复习之指向函数指针数组的指针、回调函数
Representation and operation of data
Easily master the library functions related to C language string and memory|
Part 59: main c:62:9: note: use option -std=c99 or -std=gnu99 to compile your code
Practice improving C Language-1
9.键盘事件
Interesting minesweeping game, C language programming