普通style
<div style="color:#f00">普通的style</div>
** vue的style**
- 方式一
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
data: {
activeColor: 'red',
fontSize: 30
}
- 方式二
<div v-bind:style="styleObject"></div>
data: {
styleObject: {
color: 'red',
fontSize: '13px'
}
}
数组语法
- 方式三
<div v-bind:style="[baseStyles, overridingStyles]"></div>
data: {
styleObject: {
color: 'red',
fontSize: '13px'
}
}
普通clss
<div class="class">普通的style</div>
.class{
color:#f00
}
vue的class
- 方式一
<div
class="static"
v-bind:class="{ active: isActive, 'text-danger': hasError }"
></div>
data: {
isActive: true,
hasError: false
}
- 方式二
<div v-bind:class="classObject"></div>
data: {
classObject: {
active: true,
'text-danger': false
}
}
- 方式三
<div v-bind:class="classObject"></div>
data: {
isActive: true,
error: null
},
computed: {
classObject: function () {
return {
active: this.isActive && !this.error,
'text-danger': this.error && this.error.type === 'fatal'
}
}
}
方式四
<div v-bind:class="['activeClass', errorClass]"></div>
data: {
errorClass: 'text-danger'
}
<div v-bind:class="[isActive ? 'activeClass' : '', errorClass]"></div>
<div v-bind:class="[{ active: isActive }, errorClass]"></div>