as shown in the figure, the effect is similar to this:
The fetch, used by the
request data would like to know whether the effect of this loading is written in the life cycle or in the fetch request?
how to achieve this effect?
as shown in the figure, the effect is similar to this:
The fetch, used by the
request data would like to know whether the effect of this loading is written in the life cycle or in the fetch request?
how to achieve this effect?
give the landlord an idea:
set state
loading: false
then set loading to true when sending a fetch request
set it to false when success / failure
then, in the render method, dynamically change whether the loading component displays
according to false | true.this is a good thing to write in the global tools file, because you can use it as long as you call the interface.
const tools = {
/**
* loading
* @return {[type]}
*/
showLoading() {
if (this.loadingCount <= 0) {
ReactDOM.render(
<div className="sy-loadingwrap">
<Spin size="large"></Spin>
</div>,
document.getElementById("sy-loading")
);
}
this.loadingCountPP;
},
/**
* loading
* @return {[type]}
*/
hideLoading() {
if (this.loadingCount === 0) return;
this.loadingCount--;
if (this.loadingCount === 0) {
ReactDOM.unmountComponentAtNode(document.getElementById("sy-loading"));
}
},
}
call tools.showLoading ()
before ajax send, and call tools.hideLoading ()
you still have to look at the scene. Personally, I have written in both the request
and the component
.
if you need to loading, at the request level, put it on the request. If you need to be in a component (you can think of it as a collection of requests), then loading can be written to the component state.
the implementation is very simple. Take the request level as an example, you only need to set different state,view before and after fetch to decide whether to render loading or not according to state.
it is recommended to use antd-Spin
1. Write the landing page with react, after calling the background data with axios, judge the route of the page to jump according to the return value, how to jump? 2.axios.get ( login login.action?username= +name+ &password= +pd, {) timeout: 1000...
setting in state: this.state = {checkList: []}; checkList initializes it with an array of the same length as JsonPage: this.setState ({checkList:checkSaveCount}); checkSavaCount is the same length as the following JsonPage. the following creates...
import React from react ; class PublicScreen extends React.Component { constructor(props) { super(props); this.getStyle = this.getStyle.bind(this); } getStyle() { const { width = 1920, height = 1080 } = this.pr...
renderdphtmldvareturnapiBackend: apiBackend ...
react projects cannot save store? using redux, data index.js ReactDOM.render( <Provider store={store}> <Router > < Provider>, document.getElementById( root )) registerServiceWorker() actions export const SET_USER = ...
this method is included in the constructor of most components, so what exactly is this method for constructor(props,context){ super(props,context) } ...
use the Table component of Antd Design, first check out the data, and then select a CheckBox, but when you change pages, that CheckBox will not disappear. For example, when I select the first line on the first page, and then skip to the second page, the ...
I can run before packaging without any error reports. This problem occurs after packaging. reports such an error in the browser, using scaffolding made by create-react-app, and the back end is Node.js, backend. No error is reported: packages two diff...
segmentfault dvaws.open().websocketwebsocketws ws.openfetchGETloginsendfetchCOOKIECOOKIEFETCHCOOKIECOOKIE ...
...
now we need to develop a website to generate front-end pages based on the node ID saved in the database. For example, the json data is: let data=[ {"id":1,"pid":0,"type":"div"}, {"id":2,"pi...
I pass values through redux scenario is when I click on the navigation bar of component 1 and refresh the ajax of component 2 is the data returned by ajax accepted by this.state.contnet what should I write? There is an urgent need for ideas. ...
official example of full copy: this is the official sample code: import { Select } from antd ; const Option = Select.Option; function handleChange(value) { console.log(`selected ${value}`); } ReactDOM.render( <div> <Select defaul...
how to use react to change the value of Input < hr > export default class myForm extends Component{ constructor(props){ super(props); this.state = { id: , }; } change=()=>{ var idIn...
want to set the meta tag to solve the adaptive problem <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> meta LOGO ...
use list as the option data source for Select, but use callback, which cannot be rendered. Just call it directly, as shown in the figure below. The first method is fine, and the second is not. Because there are many Select, on a page, you need to use th...
< H1 > github address < H1 > error will be reported when using npm run dev const path = require( path ); const merge = require( webpack-merge ); const common = require( . webpack.common.js ); dev-server let BundleAnalyzerPlugin = require( ...
import React from react ; import ReactDOM from react-dom ; import . assets styles index.less ; import Green from . assets images green.png ; import Red from . assets images red.png ; class Circle extends React.Component { constructor...
There are two areas in the State and Lifecycle section that I don t quite understand 1. State Updates are Merged The merging is shallow, so this.setState ({comments}) leaves this.state.posts intact, but completely replaces this.state.comments. ...
like this [array [xxx], array [xxx], array [xxx].] merge all xxx in array into one array [xxx.] ...