react-antd组件 input输入框: 实现按回车搜索

目录

法1:

法2:


法1:

在Input组件上绑定onKeyUp方法

javascript 复制代码
import { Input, message } from 'antd';

class App extends React.Component{

    handeleSousuo = () => {
        this.props.form.validateFields((error, values) => {
            if(!error){
                axios.post().then(res => {
                    if(res.code === 200){
                        
                    } else {
                        message.error('出错啦,刷新试试!')
                    }
                })
            }
        })
    }

    inputKeyUp=(e)=>{
        console.log(e, 'e')
        if(e.keyCode === 13){
            this.handeleSousuo(); //调搜索接口 
        }
    }


    render(){
        return(
            <div>
                <Input onKeyUp={this.inputKeyUp} />
            </div>
            
        )
    }
}

法2:

antd组件里搜索框

javascript 复制代码
import { Input } from 'antd';

const { Search } = Input ;

class App extends React.Component{

    search = () => {
        this.props.form.validateFields((error, values) => {
            if(!error){
                axios.post().then(res => {
                    if(res.code === 200){
                        
                    } else {
                        message.error('出错啦,刷新试试!')
                    }
                })
            }
        })
    }

   
    render(){
        return(
            <div>
                <Search onSearch={() => this.search()} />
            </div>
            
        )
    }
}
相关推荐
tachibana29 小时前
与其他语言相比,使用 Go 有什么好处?
开发语言·后端·golang·go
阿俊-全栈开发13 小时前
LikeShop 单商户SaaS商城分销模块二开:佣金计算与结算逻辑实现
java·开发语言·微服务·likeshop·likeshop开源商城·likeshop多商户
奕鼎竜瑆15 小时前
Solid 前端响应式开发从零到精通
前端·人工智能
动恰客流统计15 小时前
景区客流统计怎么做?兼顾管控与运营的实施方案解析
大数据·前端·人工智能
派小心.16 小时前
A/B测试工具免费版够用吗?
前端·数据分析
m0_3807438716 小时前
C++中的freopen的用法实例详解
开发语言·c++
前端snow17 小时前
ai agent --- redis 缓存
前端
Escalating_xu17 小时前
【Python】基础语法(1):常量、变量、类型、输入输出与运算符
开发语言·python
jimy117 小时前
polymorph.cpp里面的“析构函数、智能指针”问题
开发语言·c++
m0_3807438717 小时前
PHP 8.3 缓存清除不生效怎么排查
开发语言·php