<div v-bind:class="classObject"></div>
data() {
return {
isActive: true,
error: null
}
},
computed: {
classObject: function () {
return {
active: this.isActive && !this.error,
'text-danger': this.error && this.error.type === 'fatal'
}
}
}
vue中,内联样式可以通过这种方式来完成。
uni-app中,官方写法如下:
<view :style="{color:color}" />
那么,uni-app中不能采用跟vue同样的写法吗?
尝试使用vue方式写:
<view class="run_one" :style="getRunOneBg"></view>
computed: {
getRunOneBg() {
return {
background: 'url(' + this.runOneBg + ') 0 0/100% 100% no-repeat'
};
}
},
结果:
<viewclass="_view fdfd28ca run_one"style=" [object Object]"role=""aria-label=""></view>
2 个回复
Trust - 少说废话
Class 与 Style 绑定
哈库拉玛塔塔 - 简单又好吃
新发现问题,动态改颜色啥的这些样式没问题,如果改高度会出现不渲染的bug data中设置一个随机数 定时更新下随机数的值会触发高度渲染。狗的不行。。