Create a project using React-create-app
- Global installation NPM Install-g Create-react-app
- Create Project Create-react-app + project name
Introducing the Sass processor writing style
Installation:
"Node-sass-chokidar" "^1.3.0","Npm-run-all" "^4.1.3",
Package.json as follows:
"Scripts": {"Build-css":"Node-sass-chokidar Src/assets/sass-o Src/assets/css","Watch-css":"NPM run build-css && node-sass-chokidar src/assets/sass-o src/assets/css--watch--recursive","Start-js":"React-scripts Start", "Start": npm-run-all-p Watch-css start-js" Build-js ": " react-scripts build ", "Build": Npm-run-all build-css Build-js "Test": "react-scripts test--env=jsdom", "Eject":
Configuration method
Configure Proxy to Node layer
"Proxy": { "/api" target"http://localhost:4222/"}}
Use
Node Layer configuration:
App.use ('/api/productsve ', productsve);
Router.get ('/getproducts ', function (req, res) {
var results = {
Id:1,
Title: ' Computer ',
price:5000,
}
Res.json (results);
});
Used in react:
Componentdidmount () {
Fetch ('/api/productsve/getproducts ')
. Then (res = {
Res.json ()
})
. Then (data = {
Console.log (data)
})
. catch (Err = {
Console.log (ERR)
})
}
Problems and Solutions
- Packing times wrong: Import in body of module; Reorder to top Import/first
Build projects based on React-create-app and Nodejs