首页 > 其他分享 >Vue技术7.2事件修饰符

Vue技术7.2事件修饰符

时间:2022-12-27 13:05:58浏览次数:35  
标签:Vue background color 修饰符 7.2 事件 提示信息


<!DOCTYPE html>>
<html>
<head>
<matta charset="UTF-8" />
<title>事件修饰符</title>
<!-- 引入Vue -->
<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.atguigu.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.passive="demo" class="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>

</body>

<script type="text/javascript">
Vue.config.productionTip = false

new Vue({
el:'#root',
data:{
name:'尚硅谷'
},
methods:{
showInfo(e){
// e.preventDefault()
//e.stopPropagation()
alert('同学你好!')
},
showMsg(msg){
console.log(msg)
},
demo(){
for (let i = 0; i < 100000; i++) {
console.log('#')
}
console.log('累坏了')
}
}
})
</script>
</html>


标签:Vue,background,color,修饰符,7.2,事件,提示信息
From: https://blog.51cto.com/u_15923796/5972661

相关文章

  • Vue技术8.2姓名案例_methods实现
    <!DOCTYPEhtml>><html><head><metacharset="UTF-8"/><title>姓名案例_methods实现</title><!--引入Vue--><scripttype="text/ja......
  • Vue技术8.2姓名案例_methods实现
    <!DOCTYPEhtml>><html><head><metacharset="UTF-8"/><title>姓名案例_methods实现</title><!--引入Vue--><scripttype="text/ja......
  • vue3_05使用reactive来处理复杂数据
    vue3中除了提供了ref函数以为还提供了reactive函数来操作数据,一般情况下我们使用ref函数来操作简单类型数据,reactive函数来操作复杂类型数据<template><div>{{objRet.na......
  • vue3_03ref操作复杂类型
    ref也可以将复杂类型的数据转换为响应式数据,使用方法和处理简单类型数据一样leta=ref(复杂类型数据)a.value.xxx<template><p>{{objref.num}}</p><button@c......
  • vue3_04ref获取标签
    ref也可以用来获取dom节点分为三步:1.给节点绑定ref='xxx'2.letxxx=ref()3.在挂载之后直接使用即可<template><divref="op">24</div><p>{{num}}</p>......
  • vue3中使用vuex
    一、使用习惯1(模块化):1、文件目录:2、userStore.tsimport{Module}from'vuex';//import{setStorage,getStorage}from"../../util/common";exportdefault{......
  • vue3_02ref操作简单类型
    vue3中提供了ref()函数可以把数据转换为响应式数据。<template><div>{{num}}</div><button@click="add">这是按钮</button></template><sc......
  • Vue3之setup的两个注意点
    setup的两个注意点setup执行的时机在beforeCreate之前执行一次,this是undefined。setup的参数props:值为对象,包含:组件外部传递过来,且组件内部声明接收了的属性。......
  • 关于Vue3 can not find module的报错
    最近在做Vue3项目的时候,会看到这样一个报错,找不到模块.vue文件,可能是ts文件无法识别vue后缀的文件导致的,上网搜索了一下发现尤大大给出了解决方案。在src目录下新建一个.......
  • Vue3之reactive和ref对比
    reactive对比ref从定义数据角度对比:ref用来定义:基本类型数据。reactive用来定义:对象(或数组)类型数据。备注:ref也可以用来定义对象(或数组)类型数据,它内部会自动通过re......