const Login = ({ login, username, userId }) => {
  sessionStorage.setItem('userId', userId);
  sessionStorage.setItem('username', username);  return (
    <div className="mob-paper2">
      <div className="m-logo-big">
        <img style={{ width: 70, height: 70 }} src={tsIoin} alt="" />
        <h1>11111</h1>
      </div>
      <div>
        <h1 className="m-software">1111</h1>
      </div>
      <br/>
      <form onSubmit={login(this.refs.name.value, this.refs.pass.value)}>
        <table className="fill-table fixed-table auto-margin">
          <tr>
            <th width="100">账号:</th>
            <td width="220"><input style={{ width: 200 }} name="username"
              type="text" className="txt-box" ref="name" /></td>
          </tr>
          <tr>
            <th>密码:</th>
            <td><input style={{ width: 200 }} name="password" type="password"
              className="txt-box" ref="pass" /></td>
          </tr>
          <div style={{ width: 470 }} className="dengru">
            <button className="m-dengru" type='submit' value='登入'>
              {(username && username.length > 0) ? (<Link to='/price' />) : (<Link to='/' />)}
            </button>
          </div>
        </table>
      </form>
    </div>
  )
}Login.propTypes = {
  login: PropTypes.func.isRequired,
  username: PropTypes.object.isRequired,
  userId: PropTypes.number.isRequired
}export default Login一直显示onSubmit中login()方法的2个值取不到

解决方案 »

  1.   

    ref="pass" 这种字符串用法react新点的版本已经删除不用了
    在有检查下你的this是否指向了组件实力
      

  2.   

    <table className="fill-table fixed-table auto-margin">
            <tr>
              <th width="100">账号:</th>
              <td width="220"><input style={{ width: 200 }}  name="username"
                type="text" className="txt-box" onChange={this.handleChangeUsername} value={uname}/></td>
            </tr>
            <tr>
              <th>密码:</th>
              <td><input style={{ width: 200 }}  name="password" type="password"
                className="txt-box" onChange={this.handleChangePassword} value={uId}/></td>
            </tr>
            <div style={{ width: 470 }} className="dengru">
              <button className="m-dengru" onClick={login(uname,uId)}>
                    {(username && username.length > 0 )? (<Link to='/price' />) : (<Link to='/' />)}登入
              </button>
            </div>
          </table>
      </div>
    然后报了这个错