HarmonyOS textinput组件的text属性通过set state方式不生效

HarmonyOS
2024-12-20 17:38:07
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple
@Entry
@Component
struct TextInputPage {
  @State message: string = '';

  build() {
    Column() {
      TextInput({ text: `${this.message}` })
        .height(48)
        .onChange(str => {
          this.message = str;   //这行必须得加
          console.info('...str:' + str);
          if(str.length > 3){
            this.message = str.substring(0, 3)
          }
        })
    }
    .width('100%')
  }
}"
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
分享
微博
QQ
微信
回复
2024-12-20 19:26:33
相关问题
通过WindowProperties设置属性生效
3017浏览 • 1回复 待解决
List组件initialIndex属性设置生效
2959浏览 • 1回复 待解决
textfield截断属性生效
3471浏览 • 1回复 待解决
用数组变量控制组件属性生效
2361浏览 • 1回复 待解决
HarmonyOS Web组件borderRadius生效
1066浏览 • 1回复 待解决
容器组件onVisibleAreaChange生效
2781浏览 • 1回复 待解决
HarmonyOS text组件设置width
763浏览 • 1回复 待解决
HarmonyOS 组件切换深色模式生效
1260浏览 • 1回复 待解决
HarmonyOS ArkWeb组件加载url生效
1052浏览 • 1回复 待解决