最近我正在研究react.js crud应用程序我喜欢使用react.findDomNode来创建记录
handleSubmit: function(e) {
e.preventDefault();
name = React.findDOMNode(this.refs.name).value.trim();
email = React.findDOMNode(this.refs.email).value.trim();
address = React.findDOMNode(this.refs.address).value.trim();
state = React.findDOMNode(this.refs.state).value.trim();
zip = React.findDOMNode(this.refs.zip).value.trim();
city = React.findDOMNode(this.refs.city).value.trim();
但我面临以下错误我如何重新获得它我也使用
答案 0 :(得分:1)
您应该使用ReactDOM包。
import ReactDOM from 'react-dom'
const name = React.findDOMNode(this.refs.name).value.trim();
但在你的情况下你可以使用refs来获取价值:
handleSubmit(e) {
e.preventDefault();
const name = this.refs.name.value.trim(),
email = this.refs.email.value.trim(),
address = this.refs.address.value.trim(),
state = this.refs.state.value.trim(),
zip = this.refs.zip.value.trim(),
city = this.refs.city.value.trim();
}