你離它很近。 當前實現在<input>字段更改后立即生成搜索url。如果需要其他過濾器,則需要在實際生成url和獲取數據之前將這些過濾器值存儲在狀態中。 以下是要點。 class Patient extends React.Component { constructor(props) { super(props) this.state = { patients : [], filters: {q: '', gender: ''} // we add the filter property to the state }; this.updateFilter = this.updateFilter.bind(this); } // this will fetch the new patients as soon as one of the filter has been updated fetchPatients() { const searchParams = new URLSearchParams(); const {q, gender} = this.state.filters if (q) { searchParams.set('q', q); } if (gender) { searchParams.set('gender', gender); } const u