📌  相关文章
📜  表单 onCLick() 中的多个项目 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:40.539000             🧑  作者: Mango

代码示例1
class App extends React.Component {
  state = {
    post: {
      name: "",
      description: ""
    },
    jobs: []
  };

  handleChange = e => {
    const { name, value } = e.target;

    this.setState(prevState => ({
      post: { ...prevState.post, [name]: value }
    }));
  };

  handleSubmit = e => {
    e.preventDefault();

    this.setState(prevState => ({
      jobs: [...prevState.jobs, prevState.post],
      post: { name: "", description: "" }
    }));
  };

  render() {
    return (
      

Welcome to React

    {this.state.jobs.map((job, index) => (
  • {job.name}: {job.description}
  • ))}
); } } ReactDOM.render(, document.getElementById("root"));