【问题标题】:Need to get events using a TicketMaster API with Axios and React.js需要使用带有 Axios 和 React.js 的 TicketMaster API 获取事件
【发布时间】:2018-07-08 07:07:21
【问题描述】:

我有一个带有邮政编码表单和提交按钮的反应组件。我需要使用 axios 来提取我的 TicketMaster api 密钥并加载提交按钮单击时输入的邮政编码中的所有事件。

我知道我需要做一个 axios.get() 但不知道在哪里或如何放置它。

我在这里设置了状态:

class Menu extends React.Component {
constructor() {
    super()
    this.state = {
        events: [],
        postalCode: "",
        searchTerm: ""
    };
    console.log(this.state);
}

这是带有邮政编码和提交按钮的表单:

render() {
    return (
        <div>
        <div className="panel panel-default" >
            <div className="panel-heading">
                <h3 className="panel-title">Menu</h3>
                <h2 className="panel-title">
                    Zip Code: <input
                        type="text"
                        name="zipCode"
                        value={this.state.event}
                        onChange={this.handleInputChange}
                    />
                </h2>
                <button
                    onClick={this.handleFormSubmit}
                    type="success"
                    className="input-lg"
                >Submit</button>
            </div>

【问题讨论】:

  • 你试过在handleFormSubmit做一个请求吗?

标签: reactjs axios


【解决方案1】:

在 handleFormSubmit 上调用 axios

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 1970-01-01
    • 2021-06-01
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多