美文网首页
vue 渐变色内联写法 动态赋值

vue 渐变色内联写法 动态赋值

作者: CoderZb | 来源:发表于2021-12-27 23:16 被阅读0次
image.png

注意:color1color2是动态的变量,用于设置到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>

相关文章

网友评论

      本文标题:vue 渐变色内联写法 动态赋值

      本文链接:https://www.haomeiwen.com/subject/onuuqrtx.html