Reactjs 调用Axios成功后如何更新页面?反应

Reactjs 调用Axios成功后如何更新页面?反应,reactjs,Reactjs,因此,我正在做一个项目,使用Axios和Json服务器,但我有一个问题,每次我做补丁,我必须在主页上给F5更新,我想知道我如何才能做到这一点,使它不会自动发生 我的修补程序: onSubmitDate=event=>{ const newUrl=prompt(“请使用新URL:”); const personCurrent=event.target.value; 腋斑(`http://localhost:3004/employee/${personCurrent}`{ url\u git:new

因此,我正在做一个项目,使用
Axios
Json服务器
,但我有一个问题,每次我做
补丁
,我必须在主页上给F5更新,我想知道我如何才能做到这一点,使它不会自动发生

我的
修补程序
onSubmitDate=event=>{
const newUrl=prompt(“请使用新URL:”);
const personCurrent=event.target.value;
腋斑(`http://localhost:3004/employee/${personCurrent}`{
url\u git:newUrl
})
。然后(响应=>{
控制台日志(响应);
})
.catch(错误=>{
console.log(错误);
});

}
我假设更新发生在您正在处理的组件上

要创建组件的重新渲染,只需设置状态即可。 你的答复是什么格式的?它是否包括您希望显示的更新数据?如果是这种情况,很简单,只需在
中执行
设置状态
,然后

  onSubmitDate = event => {
    const newUrl = prompt("Please with new URL:");
    const personCurrent = event.target.value;
    axios.patch(`http://localhost:3004/employee/${personCurrent}`, {
    url_git: newUrl
  })
  .then(response => {
    console.log(response);
    this.setState({employee: response.data})
  })
  .catch(error => {
    console.log(error);
  });
}
如果响应没有提供您希望在组件中更新的数据,您只需在补丁的
然后
中获取您想要的任何数据,并设置其响应的状态。比如说:

  onSubmitDate = event => {
    const newUrl = prompt("Please with new URL:");
    const personCurrent = event.target.value;
    axios.patch(`http://localhost:3004/employee/${personCurrent}`, {
    url_git: newUrl
  })
  .then(response => {
    console.log(response);        
    axios.get("http://127.0.0.1:3004/employee")
      .then(response => this.setState({ employee: response.data }));

  })
  .catch(error => {
    console.log(error);
  });
}

您可以使用setInterval()或使用软件包吗?是的,我让它做同样的事情:(有几件事:你得到了你期望的响应吗?你只是使用了一个补丁还是一个接一个get的补丁?补丁后接一个get,firt get,在我做了补丁之后,你能在OP上更新你的代码吗?这样会更容易看到并找出哪里出了问题