大家好,都吃了吗?我是Kaiqisan,是一个不善言辞的羞射男孩。当解决这个问题的时候,我骂了自己7遍sb
taro的组件当然有taro自己的解决方案,官网里面都有
解决方案
把onChange
替换成 onInput
import React from 'react'
import { View, Text, Input, Checkbox, Button } from '@tarojs/components'
export default class Cmp3 extends React.Component {
constructor(props) {
super(props)
this.state = {
Info: '',
}
}
render() {
const { Info } = this.state
return <View>
<Input style={'border: 1px solid #000; width: 200px; padding: 10px 10px'} value={Info} onInput={(e) => {
this.InfoChange(e)
}}/>
<Text>{Info}</Text>
</View>
}
InfoChange(e) {
this.setState({
Info: e.target.value
})
}
}
这样就可以实现双向绑定了。
实现效果(使用taro小\程序运行)
总结
多看看官方文档,不要一天天抱着痴心妄想,脚踏实地!