a组件在text组件内不能动态修改样式,怎么破?

问题描述:java

a组件放到text组件内部,a组件的style中文字颜色是动态绑定的,修改绑定textcolor的值,没法改变a组件的文字颜色,好比我但愿文字颜色能从原始颜色蓝色变成红色。代码以下所示:app

template中代码:框架

<text>
            <a href="https://huawei.com" style="color: {{textcolor}};" value="click here"></a>
        </text>
         <input type="button" value="修改a的文字颜色" onclick="changeColor" />

script中代码:ide

changeColor: function() {
          this.textcolor="red";
        }

问题分析:ui

a组件放到text组件内部时,快应用框架不支持动态改变样式。this

解决办法:spa

借助text去实现a的动态效果,直接在text组件上绑定样式(a组件自身不绑定),能够达到效果,代码以下(见红色部分):code

**<text style="color: {{textcolor}};">blog

<a href="https://huawei.com" value="click here"></a>

</text>**图片

效果图(点击按钮后):
在这里插入图片描述

欲了解更多详情,请参阅:

快应用开发指导文档:https://developer.huawei.com/consumer/cn/doc/development/quickApp-Guides/quickapp-whitepaper


原文连接:
https://developer.huawei.com/consumer/cn/forum/topic/0204399557167870123?fid=18

做者:AppGallery Connect

相关文章
相关标签/搜索