vue(uniapp)中动态样式 class && style
1.style样式动态设置
<template>
<view>
<view :style="{color:fontColor}"> </view>
<view :style="{ paddingTop: num + 'px' }"></view>
<view :style="{backgroundImage: 'url(' + imageURL + ')','background-repeat':'no-repeat',
backgroundSize:'100% 100%'}">
</view>
<view :style="[{paddingTop: num + 'px'},{color:fontColor}]"></view>
<view :style="[{color:(flag?'green':fontColor)}]"></view>
</view>
</template>
<script>
export default {
data() {
return {
imageURL: 'https://app-file.beitaichufang.com/img/H5/web/banner/banner23.jpg',
num:20,
fontColor:'red',
flag:true,
}
}
}
</script>
2.class样式动态设置
<template>
<view>
<!--第一种写法-->
<view :class="[isRed?'red':'green']"></view>
<!--简写法-->
<view :class="{red:isRed}"></view>
</view>
</template>
<script>
export default{
data(){
return{
isRed: true
}
}
}
</script>
<style>
.red{
color:#DD524D;
}
.green{
color:#00FF00
}
</style>