首页 > 其他 > 详细

fucsion的form教程

时间:2021-03-29 00:07:28      阅读:39      评论:0      收藏:0      [点我收藏+]
import React, { useState } from ‘react‘
import { Button } from ‘@alifd/next‘;
import { Input, Button, Field } from ‘@alifd/next‘;

function index() {
    const field = Field.useField();

    const { init, setValue, reset, getError } = field;

    function onGetValue() {
        console.log(field.getValue("input"));
    }

    function onSetValue() {
        field.setValue("input", "xyz");
    }
    return (
        <div className="demo">
            <Input
                {...init("input", {
                    initValue: "test",
                    rules: [
                        {
                            required: true,
                            pattern: /hello/,
                            message: "must be hello"
                        }
                    ]
                })}
            />
            <span style={{ color: "red" }}>{getError("input")}</span>

            <br />
            <br />
            <Button onClick={onSetValue}>setValue</Button>
            <Button onClick={onGetValue}>getValue</Button>
            <br />
            <br />
            <pre style={{ marginTop: 8 }}>
                {JSON.stringify(field.getValues(), null, 2)}
            </pre>
        </div>
    );

}

export default index

 

fucsion的form教程

原文:https://www.cnblogs.com/sexintercourse/p/14589997.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!