第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

REACT:翻譯組件 | 設(shè)置和訪問狀態(tài)

REACT:翻譯組件 | 設(shè)置和訪問狀態(tài)

我正在創(chuàng)建一個(gè) REACT 組件,該組件通過基本上獲取用戶的輸入并使用簡單的鍵值對(duì)訪問翻譯來“翻譯”一個(gè)數(shù)字。除了我的 handleTranslate 方法外,一切正常。此方法的控制臺(tái)日志給我未定義。class MyComponent extends React.Component {  constructor(props) {    super(props);    this.state = {      input: '',      one: 'uno',      two: 'dos',      three: 'tres',      four: 'cuatro',      five: 'cinco',      six: 'seis',      seven: 'siete',      eight: 'ocho',      nine: 'nueve',      ten: 'diez',      answer: ''    };    this.handleChange = this.handleChange.bind(this);    this.handleTranslate = this.handleTranslate.bind(this);  };    handleChange(state) {    this.setState({      input: event.target.value    });  }  handleTranslate (state) {    var x = state.input;    this.setState({      answer: state.x    });  }    render () {  return(  <div>      <h3>Enter an English number between one and ten and watch the translation render below</h3>      <input value={this.state.value} onChange={this.handleChange, this.handleTranslate}/>      <p>{this.state.input}</p>  </div>  );  }};ReactDOM.render(<MyComponent/>, document.getElementById('view'));<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script><div id='view' />
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊

使用一個(gè)處理函數(shù)event就可以了


class App extends React.Component {

  constructor(props) {

    super(props);

    this.state = {

      input: "",

      one: "uno",

      two: "dos",

      three: "tres",

      four: "cuatro",

      five: "cinco",

      six: "seis",

      seven: "siete",

      eight: "ocho",

      nine: "nueve",

      ten: "diez",

      answer: ""

    };

    this.handleChange = this.handleChange.bind(this);

  }


  handleChange(event) {

    this.setState({

      input: event.target.value

    });

    this.setState({

      answer: this.state[event.target.value]

    });

  }

  render() {

    return (

      <div>

        <h3>

          Enter an English number between one and ten and watch the translation

          render below

        </h3>

        <input value={this.state.value} onChange={this.handleChange} />

        <p>{this.state.input}</p>

        <p>{this.state.answer}</p>

      </div>

    );

  }

}


ReactDOM.render(<App />, document.getElementById("root"));

<div id="root"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.12.0/umd/react.production.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.12.0/umd/react-dom.production.min.js"></script>



查看完整回答
反對(duì) 回復(fù) 2022-06-16
  • 1 回答
  • 0 關(guān)注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)