这是我第一次使用ReactJS,但我不断收到错误消息
'userData'未定义为un-undef
即使我声明了它。这是我的代码:
class Register extends Component {
constructor(props) {
super(props);
this.state = {
userData: [],
fullName: "",
email: "",
uname: "",
pass: ""
}
}
onRegis = () => {
const { fullName, email, uname, pass } = this.state
userData = [{fullName, email, uname, pass}]
this.setState({
userData
})
console.log("Datanya euy: ", userData)
// console.log(email, " is ", fullName, "'s email addres with username ", uname, " and password ", pass);
}
}`
答案 0 :(得分:1)
您忘记通过userData
,var
或let
定义变量const
const userData = [{fullName, email, uname, pass}];