简体   繁体   English

如何将 Ajax 进度条添加到 React.js 应用程序?

[英]How to add Ajax progress bar to React.js application?

I have a submitForm();我有一个 submitForm(); function to send an Ajax request and return data.发送 Ajax 请求并返回数据的函数。 How can I show a progress bar in my program.如何在我的程序中显示进度条。

I am using jQuery to send Ajax.我正在使用 jQuery 发送 Ajax。

Without mentioning third party libraries (there are plenty out there that have API's for you to call to do it for you)没有提到第三方库(有很多有 API 供您调用来为您完成)

The most naive way is to dispatch something like a isLoading Action, the same time you fire off your API call.最简单的方法是dispatch类似isLoading Action 的东西,同时触发 API 调用。 Then have the components you want subscribe to that part of the store, and display a whatever you please.然后让你想要的组件订阅商店的那部分,并显示你喜欢的任何内容。 So you can have render() code that looks like所以你可以有render()代码看起来像

if(this.props.isLoading){
    return <span> Loading... </span> //or whatever progress bar you want
}
else{
    //your code
}

And then when your API responds, you just set isLoading back to false, and then your components can use the responses.然后当您的 API 响应时,您只需将isLoading设置回 false,然后您的组件就可以使用这些响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM