React js:将道具传递到React Router的Link组件

时间:2019-12-17 14:37:37

标签: javascript reactjs react-router react-props

嘿,我尝试在获取数据后重定向到另一个,但我能够重定向,但是当我在结果页面中使用COPY --chown=1000:1000 environment.yml requirements.txt postBuild ./时,它在控制台中的显示为this.props.location.state,这是我的所有代码,请问这段代码中的错误在哪里。 Search.js

[object Object],[object Object],[object Object],[object Object],[object Object]

async handleSubmit(e) { let authToken = localStorage.getItem("Token"); try { const from = e.target.elements.from.value; const to = e.target.elements.to.value; const selections = [...e.target.elements.selectOptions.options].filter( opt => opt.selected ); const selectedValues = selections.map(opt => opt.value); const selectedString = selectedValues.join(","); e.preventDefault(); const res = await fetch( `http://localhost:8000/api/1/deliveries/report/?date__lte=${to}&date__gte=${from}&user=${selectedString}`, { method: "GET", headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: "Bearer " + JSON.parse(authToken) } } ); const movie = await res.json(); console.log(movie); this.setState({ movie }); // this.props.history.push("/driverreport"); this.props.history.push({ pathname: "/driverreport", state: movie }); } catch (e) { console.log(e); } } 中,我只是在控制台中检查数据,但是我正在获取这样的数据`   result.js

result.js

1 个答案:

答案 0 :(得分:-1)

请参阅此link,以获取更多详细信息。

您可以通过以下示例访问数据:-

 
 let data = {
 name:'John',
 id:123,
 movie:"ABC"
 }
 
 // Using "+" in console.log() it shows Don: [object Object]
 console.log("Don: " + data);
 
 //But you can access it by :-
 console.log("Don: " + data.movie);
 
 // Using "," in console.log() it shows entire data object with key value pair
 console.log("Don: " , data);