指令修饰符

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            width: 200px;
            height: 200px;
            background-color: skyblue;
        }

        .son {
            width: 50px;
            height: 50px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1>@keyup.enter ---> 键盘回车监听</h1>
        <input type="text" @keyup.enter="fn" v-model="userName">

        <h1>v-model修饰符</h1>
        <h3>v-model.trim ---> 去除首尾空格</h3>
        <input type="text" v-model.trim="user">
        <h3>v-model-number -----> 转数字</h3>
        <input type="text" v-model.number="num">

        <h1>事件修饰符</h1>
        <h3>@事件名.stop ----> 阻止冒泡</h3>
        <div class="father" @click="father">
            <div class="son" @click.stop="son"></div>
        </div>
        <h3>@事件名.prevent ----> 阻止默认行为</h3>
        <a href="https://yiyan.baidu.com/" @click.prevent>阻止默认行为</a>
    </div>

    <!-- 引入的是开发版本包 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>

    <script>
        const app = new Vue({
            // 通过el配置选择器,指定vue管理的是哪个盒子
            el: '#app',
            // 通过data提供数据
            data: {
                userName: '',
                user: '',
                num: ''
            },
            methods: {
                fn() {
                    console.log('键盘回车监听', this.userName);
                },
                father() {
                    alert('父级')
                },
                son() {
                    alert('子级')
                }
            }
        })
    </script>
</body>

</html>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值