Front-end rookie, would like to ask some front-end separation questions
after reading some articles with separate front and rear ends, I still need to ask for advice on some questions:
1. How do you get the backend localhost to debug when the front end of the project is separated from the local API at the front end of the project?
2. Are both front and rear separation projects spa? What should I do in the case of multiple pages?
3. Can I just pack the front-end page and give it to the back-end?
4. Do you see in some articles that handlebars, is used when node is used as the middle tier?
is there any difference in interpolation between him and vue"s {{}}? if it"s the same, why use handlebars
?
- use
http
to obtain interface data such as axios
, local localhost
to work with the backend to allow cross-domain request access. If it is the development phase, do mock
through the interface definition.
- does not have to be
spa
. Front-end separation is equivalent to publishing front-end resource files as static resource services (except for server rendering), and multiple pages are redirected through link addresses (but it is still recommended that spa
, when a complete project is processed, rather than page by page).
- after the front end is packaged, you can publish it yourself (if there is an OPS to OPS), such as
nginx
.
-
handlebars
is not well understood. Check that it is a template engine. Unlike vue
, {{}}
is often used as a convention for parameter substitution. (because I don't know about handlebars
, I don't comment on the questions about handlebars
)
originally java beginners did not expect that the company would learn to develop both front and back end of vue,. At present, several projects that have been done are single-page and have not yet involved multiple pages, so they can only answer some questions,
1. To obtain the backend interface, either agree on the interface path in advance, or ask the backend developer for the interface path, and then access it through axios. After the front-end development is completed, it is generally necessary to co-debug with the back-end development, make sure that there is no bug, and then compile the front and back end and deploy them to the server for testing. As for the handlebars you mentioned, only v-moudel and {{}} are currently used in development. The former is bi-directional binding and the latter is one-way binding
.
complete separation of front and rear ends refers to the complete separation of code logic and interacts with each other only through interfaces. A front-end project in this state is actually a bunch of static resources.
The - interface requests the background through
XmlHttpRequest
or fetch
, which is the same as the ajax
technology of a long time ago.
- is not necessarily spa,spa just to facilitate developers to manage the state of app and optimize the user experience. If you have more than one page, you can write multiple html. If you are using
webpack
for engineering, add a few more entry
entries.
- the front-end page can be deployed to the service separately, and there is no need to interact with the background project.
- due to the emergence of
node.js
, the front end evolved rapidly from the original slash-and-burn cultivation. Originally, you have to write html, to write a page. Now, because the front and back are separated, we just need to make sure that the online code is compiled html,js. This means that you can play as much as you want in the development phase, just doing more things when precompiling. Mustache
, pug
, Handlebars
are all template engines. You can write pages according to their syntax and compile them into html. As for vue, it's totally different from them.
- the interpolation of the template engine is certainly not as powerful as the template language of the MV* framework, which of course means that you have to introduce a series of peripherals of vue.
1. Answer this question separately:
(1) if your local front-end project is a (java), running in the backend service, then you can directly call the http request
(2) if the front and rear ends are completely separated, then you need to set up your own service (nodejs,webpack-dev-sever,express) locally to request the interface of your back-end colleagues, sometimes you need to solve cross-domain problems.
2. Not all the projects separated from the front and rear ends are spa,. If it is a SPA single-page application, you can switch pages by managing routes.
3. This question actually asks the question of packaging and deployment, which involves who does the deployment, and it doesn't matter who does the work, but as a front end, you need to know how your packaged project is deployed to the server (linux,windows), and what's the difference between the development environment and the production environment.
4.Handlebars is a semantic template library of JavaScript that quickly builds Web templates through the separation of view and data.
and vue's {{}} interpolation is also a semantic template, but vue also implements two-way binding, which is not a concept, but is similar in usage.