我如何在反应中向 axios 发送任何变量(获取请求)

时间:2021-07-15 13:08:14

标签: reactjs api axios get get-request

我有一个 jsx 文件,它有一个输入和一个按钮。在我的 API 服务中,有一个连接到 axios 的 get 请求。如何在 axios 中发出 get 请求并打印输入中输入的值的传入数据?

我的反应代码

export default function HexFind() {

    return (
        <div>
            <Container>
                <br />
                <br />
                <form>
                    <div className="a">
                        <Image spaced="center" size="medium" src="" />
                    </div>
                    <div className="b">
                        <Input fluid placeholder='Hex ID giriniz' name="txtbox"></Input>
                    </div>
                    <div className="c">
                        <Button style={{ background: '#06AE57', color: 'white' }} >Hex Ara</Button>
                    </div>
                </form>
                <br />
                <br />
                <Grid celled>
                        <Grid.Row>
                            <Grid.Column width={4}>
                                Hex ID: 
                            </Grid.Column >
                            <Grid.Column width={4}>
                                Reason:
                            </Grid.Column>
                            <Grid.Column width={4}>
                                Date:
                            </Grid.Column>
                            <Grid.Column width={4}>
                                Server:
                            </Grid.Column>
                        </Grid.Row>
                </Grid>
            </Container>
        </div>
    )
}

我的 axios 连接服务

    import axios from 'axios'

export default class SearchService{
    searchHex(hexId) {
        return axios.get("http://localhost:8080/api/datas/getByHexId?hexId="+hexId)
    }
    
}

这是我的 api swagger 屏幕

click for image

0 个答案:

没有答案