Vue 指令v-bind和v-on,事件修饰符

(1)v-bind、v-on
v-bind的基本用法是动态更新HTML元素上的属性,如id,class,href,src等。
v-on,点击事件上

<style>
    .left{
        color:red;
    }
</style>
<body>
<div id="app">
    <div v-bind:class="{left:isleft}">{{message}}</div>
    <div v-on:click="change">点击此处改变isleft的值</div>
</div>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            message:"你好!",
            isleft: true
        },
        methods: {
           change:function(){
               if(this.isleft===true){
                   this.isleft=false;
               }else{
                   this.isleft=true;
               }
           }

        }
    })
</script>
</body>

三元表达式:

<div id="app">
    <div v-bind:class="[is?classLeft:classRight]">{{message}}</div>
</div>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            message: "你好!",
            is:true,
            classLeft:"left",
            classRight:"right"

        },
    })
</script>

缩写

<!--v-bind完整语法 -->
<a v-bind:href="url"></a>
<!-- 缩写 -->
<a :href="url"></a>


<!-- v-on完整语法 -->
<a v-on:click="doSomething"></a>
<!-- 缩写 -->
<a @click="doSomething"></a>

1.事件修饰符

.stop 阻止事件冒泡,只会触发点击事件的那一层
.prevent 提交时不再重载页面
.capture 当元素发生冒泡时,优先触发该绑定事件
.self 只有点击该事件才会执行
.once事件只会触发一次
.passive不会阻止事件的默认行为

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值