Reactjs:如何自定义多个电子邮件添加和编辑的字段

2024-03-29

在我的项目中,有一个表单字段可以添加多封电子邮件。为此,我正在使用“react-multi-email”包,通过使用此包可以添加和删除电子邮件标签,但现在我也想要编辑操作。我是 ReactJS 的初学者,所以我不知道如何自定义或添加任何额外的功能来实现这一目标。请给我一些宝贵的建议来克服这个问题。

索引.tsx

import * as React from "react";
import { render } from "react-dom";
import { ReactMultiEmail } from "react-multi-email";
import "react-multi-email/style.css";

const styles = {
  fontFamily: "sans-serif",
  width: "500px",
  border: "1px solid #eee",
  background: "#f3f3f3",
  padding: "25px",
  margin: "20px"
};

interface IProps {}
interface IState {
  emails: string[];
}

class App extends React.Component<IProps, IState> {
  state = {
    emails: []
  };

  render() {
    const { emails } = this.state;

    return (
      <div style={styles}>
        <h3>react-multi-email</h3>
        <ReactMultiEmail
          placeholder="Input your Email Address"
          emails={emails}
          onChange={(_emails: string[]) => {
            this.setState({ emails: _emails });
          }}
          getLabel={(
            email: string,
            index: number,
            removeEmail: (index: number) => void
          ) => {
            return (
              <div data-tag key={index}>
                {email}
                <span data-tag-handle onClick={() => removeEmail(index)}>
                  ×
                </span>
              </div>
            );
          }
        }
          
        />
        <br />
      </div>
    );
  }
}

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



None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Reactjs:如何自定义多个电子邮件添加和编辑的字段 的相关文章

随机推荐