事件修饰符

文章介绍了Vue.js中用于事件处理的五个重要修饰符:.stop防止事件冒泡,.capture使用事件捕获模式,.self限制事件仅在目标元素上触发,.once确保事件只触发一次,以及.prevent阻止默认的浏览器行为。这些修饰符帮助开发者更精细地控制DOM事件的处理。
摘要由CSDN通过智能技术生成

事件修饰符

1、 .stop 阻止冒泡

    <header @click="log3">
        <aside @click.stop="log2">
            <button @click="log1">log1</button>
        </aside>
    </header>

2、 .capture添加事件侦听器时使用事件捕获模式

    <header @click.capture="log3">
        <aside @click="log2">
            <button @click="log1">log1</button>
        </aside>
    </header>

3、.self 只当事件在该元素本身(比如不是子元素)触发时触发回调

    <header @click="log3">
        <aside @click.self="log2">
            <button @click.self="log1">log1</button>
        </aside>
    </header>

4、.once事件只触发一次

    <header @click.once="log3">
        <aside @click="log2">
            <button @click="log1">log1</button>
        </aside>
    </header>

5、.prevent 阻止默认事件

    <a @click.prevent="blank" href="http://www.baidu.com">百度一下</a>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值