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>
            
        )
    }
}
相关推荐
知识即是力量ol几秒前
多线程并发篇(八股)
java·开发语言·八股·多线程并发
尘缘浮梦几秒前
协程asyncio入门案例 1
开发语言·python
没有bug.的程序员4 分钟前
Lombok 深度进阶:编译期增强内核、@Data 与 @Builder 逻辑博弈及工业级避坑实战指南
java·开发语言·python·builder·lombok·data·编译器增强
guygg886 分钟前
基于人工神经网络的彩色图像恢复 MATLAB实现
开发语言·计算机视觉·matlab
zheshiyangyang1 小时前
前端面试基础知识整理【Day-7】
前端·面试·职场和发展
猫头虎1 小时前
web开发常见问题解决方案大全:502/503 Bad Gateway/Connection reset/504 timed out/400 Bad Request/401 Unauthorized
运维·前端·nginx·http·https·gateway·openresty
m0_531237171 小时前
C语言-分支与循环语句练习2
c语言·开发语言·算法
qq_24218863321 小时前
3389端口内网转发概述
前端·经验分享·html
懒惰成性的1 小时前
Java方法的使用
java·开发语言
蚊子码农1 小时前
算法题解记录-2452距离字典两次编辑以内的单词
开发语言·算法·c#