【问题标题】:how to submit form this Onchange? reactjs如何提交这个 Onchange 表格?反应
【发布时间】:2022-01-27 23:43:36
【问题描述】:

如何提交这个 Onchange 的表单?我没有触发表单的按钮,该怎么做?我无法插入路由,因为它是多个客户端的组件。我使用反应钩子形式

const handleChange = (e: any) => {
        const avatar = URL.createObjectURL(e.target.files[0])
        setAvatar(avatar)
      };

【问题讨论】:

  • 什么形式?你能添加完整的组件吗?
  • 我的表单是一个独立的组件,所有的输入和按钮都是受控组件
  • 您能否在组件中发布您的代码,以便我们了解您遇到的问题? Check this out for a template

标签: javascript reactjs typescript next.js


【解决方案1】:

您是否使用 useEffect 尝试过这个解决方案

const [avatar,setAvatar] = useState(null);

useEffect(() => {
if(avatar) handleSubmit();
}, [avatar]);

const handleChange = (e: any) => {
        const avatar = URL.createObjectURL(e.target.files[0])
        setAvatar(avatar)
      };

// suppose that this is this is your handleSubmit function 
const handleSubmit = () => {
        // your code goes here
      };

【讨论】:

    猜你喜欢
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多