前言
阻止默认行为
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>事件修饰符title>
head>
<body>
<div id="app">
<p>{{message}}p>
<a href="https://blog.csdn.net/it_heima" @click="showMes">跳转小白的博客a>
<a href="https://blog.csdn.net/it_heima" @click.prevent="showInfo">跳转小白的博客a>
div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
<script>
const app = new Vue({
el: '#app',
data: {
message: '事件修饰符学习!'
},
methods: {
showMes(e) {
console.log('被点击了!')
e.preventDefault()
},
showInfo() {
console.log('被点击了!')
}
}
});
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- .stop :阻止冒泡事件
- 如下为未阻止冒泡事件示例
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>事件修饰符title>
head>
<body>
<div id="app">
<p>{{message}}p>
<a href="https://blog.csdn.net/it_heima" @click="showMes">跳转小白的博客a>
<a href="https://blog.csdn.net/it_heima" @click.prevent="showInfo">跳转小白的博客a>
<hr>
<div style="height: 150px;background-color: orange;padding-left: 100px;line-height: 150px" @click="divHandler">
<button @click="btnHandler">按钮button>
div>
div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
<script>
const app = new Vue({
el: '#app',
data: {
message: '事件修饰符学习!'
},
methods: {
showMes(e) {
console.log('被点击了!')
e.preventDefault()
},
showInfo() {
console.log('被点击了!')
},
btnHandler() {
console.log('btn 点击事件')
},
divHandler() {
console.log('div 点击事件')
}
}
});
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>事件修饰符title>
head>
<body>
<div id="app">
<p>{{message}}p>
<a href="https://blog.csdn.net/it_heima" @click="showMes">跳转小白的博客a>
<a href="https://blog.csdn.net/it_heima" @click.prevent="showInfo">跳转小白的博客a>
<hr>
<div style="height: 150px;background-color: orange;padding-left: 100px;line-height: 150px" @click="divHandler">
<button @click="btnHandler">按钮button>
<button @click.stop="btnHandler1">按钮button>
div>
div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
<script>
const app = new Vue({
el: '#app',
data: {
message: '事件修饰符学习!'
},
methods: {
showMes(e) {
console.log('被点击了!')
e.preventDefault()
},
showInfo() {
console.log('被点击了!')
},
btnHandler(e) {
console.log('btn 点击事件')
e.stopPropagation()
},
btnHandler1() {
console.log('btn 点击事件1')
},
divHandler() {
console.log('div 点击事件')
}
}
});
script>
body>
html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61