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'
  }
}

猜你喜欢

转载自blog.csdn.net/qq_33834489/article/details/79769609