react 获取多个Input框中的值
假如页面中有很多input需要取值,如果数量少的话,可以一个一个的定义,但是如果数据多的话一个一个的处理,会造成代码冗余,工作量大的问题。
方法1
关键点就是我们传递一下name值,然后去setState里动态设置每个input的值,我们可以在render里边console.log(this.state)看一下,我们的每一项的值就是{name1:”abc”,name2:”def”}
import React,{
Component } from 'react';
class ReplenishData extends Component{
constructor(props){
super(props);
this.state = {
}
}
showVal(name,e){
this.setState({
[name]:e.target.value
});
}
render(){
console