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>
            
        )
    }
}
相关推荐
踏着七彩祥云的小丑6 小时前
pytest——Mark标记
开发语言·python·pytest
Dream of maid6 小时前
Python12(网络编程)
开发语言·网络·php
小李子呢02117 小时前
前端八股CSS(2)---动画的实现方式
前端·javascript
W23035765737 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
Y4090017 小时前
【多线程】线程安全(1)
java·开发语言·jvm
不爱吃炸鸡柳7 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
minji...8 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
Dxy12393102168 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert
GreenTea8 小时前
从 Claw-Code 看 AI 驱动的大型项目开发:2 人 + 10 个自治 Agent 如何产出 48K 行 Rust 代码
前端·人工智能·后端