vue样式

1、vue.js中内联样式style三元表达式

<span v-bind:style="{'display':config.isHaveSearch ? 'block':'none'}" >搜索</span>

--------------------------------------------------------------

class、style的绑定
1.在 v-bind 用于 class 和 style 时, Vue.js 专门增强了它。表达式的结果类型除了字符串之外,还可以是对象或数组
2.绑定css
2.1对象绑定
2.1.1绑对象格式参数
dom
div class="static"
     v-bind:class="{ active: isActive, 'text-danger': hasError }">
</div>
vue
data: {
  isActive: true,
  hasError: false
}
2.1.2直接绑对象
dom
<div v-bind:class="classObject"></div>
vue
data: {
  classObject: {
    active: true,
    'text-danger': false
  }
}
2.1.3返回对象的计算属性
dom
div v-bind:class="classObject"></div>
vue
data: {
  isActive: true,
  error: null
},
computed: {
  classObject: function () {
    return {
      active: this.isActive && !this.error,
      'text-danger': this.error && this.error.type === 'fatal',
    }
  }
}
2.1.绑定数组
dom
<div v-bind:class="[activeClass, errorClass]">
vue:
data: {
  activeClass: 'active',
  errorClass: 'text-danger'
}
2.2绑定三元表达式
<div v-bind:class="[isActive ? activeClass : '', errorClass]">
2.3绑定数组对象
<div v-bind:class="[{ active: isActive }, errorClass]">
3.绑定style
3.1对象形式绑定
dom
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
vue
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
3.2对象绑定
dom
<div v-bind:style="styleObject"></div>
vue
data: {
  styleObject: {
    color: 'red',
    fontSize: '13px'
  }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值