我正在尝试从视图详细信息页面返回到先前的搜索结果。现在,我传递到详细信息页面,并在搜索页面中检索它this.props.location.state。结果列表可能约为8,000条记录。以这种方式传递对象是个好主意吗?如果我通过querystring传递,如何使用queryParams?我尝试了一下,即使我使用JSON.stringfy,我的searchurl也显示为[object object]。请指教!
state: {
searchurl:{
filter1:[],
filter2:''
},
results:[]
}
runSearch=async()=>{
const searchurl=JSON.stringify(this.state.searchurl);
const response= await axios.get(`https://myapi/?${searchurl}`)
//${searchurl} displays as [object object]
this.setState({results: response.data});
}
//retrieve params
retrieveParams=()=>{
const query = new URLSearchParams(this.props.location.search);
const searchurl = {};
for (let param of query.entries()) {
searchurl[param[0]] = +param[1];
}
this.setState({searchurl: searchurl});
}