The latest days to learn a little react, found a few problems, estimated new into the pit of the students will also encounter, the following I first listed what time
1. Request Cross-domain issues
2. How to initiate a request
3. Simple package of Axios
Global installation of Create-react-app scaffolding to help us create a new react project
NPM install-g create-react-app
Then create the REACT project
Create-react-app XXX Project Name
Then install dependencies, and run the React project
Installing NPM Install
Run NPM start
First we solve the cross-domain problem
Open the Package.json file generated by the project and modify the file contents as follows
If you're too lazy to write like this,
Complete wording
This solves the cross-domain problem.
Let's talk about it. If you use Axios in react
Install Axios First
NPM Install Axios--save-dev
Then create a new server.js file in our src directory and write down the following code
Then we can use our Axios on the react component.
Write a react component, and then introduce our newly encapsulated server.js, write a login function, then execute the function after the component has finished rendering
Open a browser to view the results returned
Seeing the above results shows that we have successfully solved the cross-domain problem and got the data returned in the background. is not very simple, hurry up and try it yourself.
Resolving react projects in cross-domain and Axios encapsulation using