简体   繁体   English

前端(反应)与后端(快速)如何相互作用?

[英]How does front-end (React) interact with back-end (Express)?

I'm building a full stack app using MongoDB, Express, React, and Node. 我正在使用MongoDB,Express,React和Node构建一个全栈应用程序。 I've worked on projects with only front-end programming and I've worked on projects with only back-end programming. 我从事的项目只有前端编程,而我的项目只有后端编程。 I used ejs to create views for Express, so I'm not sure how it would work with front-end views created through React. 我使用ejs为Express创建视图,所以我不确定它如何与通过React创建的前端视图一起使用。 Also, I'm not sure how the CRUD operations would be used with React. 另外,我不确定CRUD操作如何与React一起使用。 I have very vague ideas. 我的想法很模糊。

What I know is that in package.json, the two are combined together when running the program. 我所知道的是,在package.json中,运行程序时将两者结合在一起。 That's about it. 就是这样 Even with that I'm unsure. 即使我不确定。 My question is: How does Express interact with React? 我的问题是:Express如何与React交互?

The kind of answers I'm looking for involve connections. 我要寻找的答案涉及连接。 Where and how does it click together? 它在哪里以及如何单击在一起? If React creates views, then how is Express connected to those views? 如果React创建视图,那么Express如何连接到这些视图? Am I importing files? 我要导入文件吗? Am I writing ExpressJS inside React components? 我是在React组件中编写ExpressJS吗? How does it display data onto the view from a database? 如何将数据从数据库显示到视图上? Is app.get('/',...) enough? app.get('/',...)是否足够? How does Express know which files to use when posting that data? Express在发布数据时如何知道要使用哪些文件?

Simple way to connect react with express add proxy in json File. 连接的简单方法是使用JSON File中的express add proxy进行响应。

 {
    "name": "create-react-app",
    "version": "0.1.0",
    "private": true,
    "devDependencies": {
        "husky": "^0.14.3",
        "lint-staged": "^7.0.0",
        "prettier": "^1.11.0",
        "react-scripts": "^1.0.17"
    },
    "dependencies": {
        "bootstrap": "^4.1.1",
        "react": "^16.2.0",
        "react-dom": "^16.2.0",
        "react-router-dom": "^4.2.2",
        "sanitize.css": "^5.0.0",
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject",
        "precommit": "lint-staged"
    },
    "proxy": "http://localhost:3000/",
    "lint-staged": {
        "*.{js,json,css,md}": [
        "prettier --write",
        "git add"
        ]
    }
 }

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

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