TextInput组件如何清空输入框内输入的内容?

搜索输入框点击搜索按钮后需要清空输入框中的内容

阅读 854
1 个回答

demo例子:

struct Index { 
  @State text: string = 'Hello World' 
  controller: TextInputController = new TextInputController() 
  build() { 
    Row() { 
      Column() { 
        TextInput({ placeholder: 'Please input your words.', text: this.text, 
          controller:this.controller}).onChange((value) => { 
          this.text = value 
        }) 
        Button("Clear TextInput").onClick(() => { 
          this.text = ""; 
        }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进