HarmonyOS 输入框不显示内容?

如题:HarmonyOS 输入框不显示内容?

阅读 544
1 个回答

问题场景

PageA 里面有组件B 组件B使用TextInput,第一次进来时候不显示内容,输入才显示

参考以下示例代码引用TextInput自定义组件

@Component
struct TextInputComponent {
  @Link text: string
  controller: TextInputController = new TextInputController()

  build() {
    Column({ space: 20 }) {
      TextInput({
        text: this.text,
        placeholder: '请输入手机号',
        controller:this.controller
      })
        .placeholderColor(Color.Gray)
        .placeholderFont({ size: 14, weight: 400 })
        .width(300)
        .type(InputType.Number)
        .borderWidth(0)
        .backgroundColor(Color.Transparent)
        .fontSize(16)
        .maxLength(11)
        .maxLines(1)
        .padding(5)
        .inputFilter("[0-9]")
        .onChange((value) => {
          this.text = value
        })
    }
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
}

@Entry
@Component
struct ParentComponent {
  @State param : string = '13670187134'
  build() {
    Column() {
      TextInputComponent({text:this.param});
      Divider().height(10)
      Text('输入框的内容:'+this.param)
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进