【快应用】如何动态设置渐变色样式
现象描述:
快应用中在<template>动态设置渐变色样式不生效,问题代码如下:
<div class="wrapper" style="background:linear-gradient({{gradient}});"></div>
问题分析
快应用中渐变色样式不支持在style中绑定变量来动态修改.
解决方法
可以通过动态改变class类名的方式来设置渐变色样式。
示例代码
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<div class="{{gradient}}">
<text class="title">{{ gradient }}</text>
</div>
<input class="button" type="button" onclick="click($idx)" value="{{$item}}" for="{{list}}" />
</div>
</template>
<style>
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.button {
width: 250px;
margin-top: 10px;
background-color: #00ced1;
border-radius: 10px;
}
.redtoblue {
background: linear-gradient(red, blue);
}
.redtogreen {
background: linear-gradient(red, green);
}
.bluetogreen {
background: linear-gradient(blue, green);
}
.redtoyellow {
background: linear-gradient(red, yellow);
}
.yellowtogreen {
background: linear-gradient(yellow, green);
}
.bluetoyellow {
background: linear-gradient(blue, yellow);
}
.title {
font-size: 100px;
}
</style>
<script>
module.exports = {
data: {
gradient: 'redtoblue',
list: ["redtogreen", "bluetogreen", "redtoyellow", "yellowtogreen", "bluetoyellow", "redtoblue"]
},
onInit() {
this.$page.setTitleBar({
text: 'menu',
textColor: '#ffffff',
backgroundColor: '#007DFF',
backgroundOpacity: 0.5,
menu: true
});
},
click(index) {
this.gradient = this.list[index]
}
}
</script>
实现效果如下:
欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
相关文章
- 【Java】【错误排查】无法将类中的构造器应用到给定类型 无法将类 uiauto.web.common.OperationNewLabelPageImpl中的构造器 OperationNewLabelPageImpl应用到给定类型;
- 【AGC】【Connect API】如何获取应用的报表分析数据
- #华为推送# 电商应用如何提高用户购买率?推送服务助您一臂之力,现在接入更有专人为您解决技术问题
- 手把手教你如何快速构建应用内消息推送与运营能力
- 《企业大数据系统构建实战:技术、架构、实施与应用》——3.2 如何选择解决方案
- 挺棒的七个Python图形应用GUI开发框架
- 《深入解析sas:数据处理、分析优化与商业应用》一1.7 本章小结
- sql语句中order by 多个字段同时排序的应用
- 指纹传感器应用和技术发展状况分析:预计2022年将达到47亿美元市场规模
- 浅析为什么使用redis、redis的4个常见问题、单线程redis为什么快、IO多路复用机制、redis数据类型及应用场景、redis过期策略及内存淘汰机制、双写一致性问题、如何应对缓存穿透/缓存雪崩问题、如何解决redis并发竞争key的问题
- 【AGC】鸿蒙应用上架的问题
- 使用华为应用签名服务后,如何生成SHA-1和MD5证书指纹
- 【快应用】如何处理服务端推送push消息,出现illegal tokens错误提示
- 使用 Autofac, MediatR 和 FluentValidator 构建松耦合 ASP.NET Core API 应用
- CAD中怎么查询图形特征?LIST命令应用技巧
- kubernetes管理应用配置之ConfigMap和Secret