事件

双向绑定

文本框内容变化,标题也变化

 1@Entry  2@Component  3struct Index {  4 @State message: string = 'Hello World'  5 checkMe = () => {  6 this.message = 'Harmony'  7 }  8 inputEvent = (event: ClickEvent) => {  9 10 } 11 12 build() { 13 Column({ 14 space: 5 15 }) { 16 Text(this.message) 17 Button('点击').onClick(this.checkMe) 18 TextInput({ 19 placeholder: '请输入内容', 20 text: $$this.message 21 }).onBlur(() => { 22 console.log('123') 23 }) 24 TextInput() 25 Divider() 26 } 27 .width('100%') 28 .height('100%') 29 } 30}
@Entry @Component struct Index { @State message: string = 'Hello World' checkMe = () => { this.message = 'Harmony' } inputEvent = (event: ClickEvent) => { } build() { Column({ space: 5 }) { Text(this.message) Button('点击').onClick(this.checkMe) TextInput({ placeholder: '请输入内容', text: $$this.message }).onBlur(() => { console.log('123') }) TextInput() Divider() } .width('100%') .height('100%') } }

普通函数

 1@Entry  2@Component  3struct Index {  4 @State message: string = 'Hello World'  5  6 checkMe() {  7 this.message = 'xxx'  8 }  9 10 build() { 11 Column({ 12 space: 5 13 }) { 14 Text(this.message) 15 Button('点击').onClick(this.checkMe.bind(this)) 16 } 17 .width('100%') 18 .height('100%') 19 } 20}
@Entry @Component struct Index { @State message: string = 'Hello World' checkMe() { this.message = 'xxx' } build() { Column({ space: 5 }) { Text(this.message) Button('点击').onClick(this.checkMe.bind(this)) } .width('100%') .height('100%') } }

Powered By 可尔物语

浙ICP备11005866号-12