问题:单独使用Ipnut组件,除了使用onChange 回调取值外,还有什么办法可以取到Input里的值,在这个场景中没有使用antd的Form组件,所有不能使用getFieldsValue。我看到Input组件里有id这个props,取值是否可以用到这个id。。
###componentDidMount() {
console.log(this.input.value);
}
<input ref={ref => { this.input = ref }} value="12345" />
###onChange={(e) => {
console.log(e.target.value)
}}
最好按照推荐用法来做。用 id 或者其他元素属性的话也是要通过 onChange 事件取
<Input data-my='33' id='55' onChange={(e) => {
console.log(e.currentTarget.getAttribute('data-my'))
console.log(e.currentTarget.getAttribute('id'))
}}>
上面这种 ref 的做法也是 ok 的
###单独使用用他的api里的value(v-model)不行吗,获取值而已,不复杂