
注意:
color1
和color2
是动态的变量,用于设置到background属性上,此时background的值既有常量又有变量了,因此必须使用拼接字符串
的方式设置background的属性值。
<div :style="{'background':'linear-gradient(to right,' + color1 + ',' + color2 +')'}" class='cus_class' ></div>
export default {
data() {
return {
color1:'red',
color2:'blue',
};
},
}
<style scoped>
.cus_class{
width:200px;
height:50px;
}
</style>
网友评论