vue 绑定 class 样式类和 style 内联样式

<template>
<div>
    <!-- v-bind:class 绑定字符串  -->
    <button :class="colorClass" >22</button>  
    <!-- v-bind:class 绑定对象 -->
    <button @click="say()" :class="{'red':isRed,'bold':isBold}">111</button>
    <!-- 数组形式绑定多个class -->
    <button :class="[colorClass,baseClass]" >33</button>
    <!-- 数组结合三目运算符绑定class -->
    <button :class="[true?colorClass:baseClass]" >33</button>
    <!-- 绑定单个style对象 -->
    <button :style="styleObject" >33</button>
    <!-- 绑定多个style对象 -->
    <button :style="[styleObject,baseStyleObject]" >33</button>
</div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      colorClass:'red',
      baseClass:'base',
      isRed:true,
      isBold:true,
      styleObject:{
        color:'blue'
      },
      baseStyleObject:{
        width:"50px",
        height:"30px"
      }
    }
  }
}
</script>

<style>
.red{
  background-color: red;
}
.blue{
  background-color: blue;
}
.bold{
  font-weight: bold;
}
.base{
  width: 100px;
}
</style>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值