What is the function of the front and rear end separation koa2?

for example, the front and rear separation project vue + axios + koa2 + java (springboot) uses restful style api
question:

  1. what role does koa2 play? Specifically, what code should be written in koa2?
  2. Under the
  3. vue+koa2 front-end combination, where should the route be written? Vue-router? Koa? Koa-router? What is the point of writing routing twice in vue and koa2?
  4. someone said that in a scenario, the backend usually does not wrap the data according to the front-end display field, but throws it over, and then disassembles and integrates it with koa2, showing to vue, is this a reason for the existence of koa2?
  5. generate a project with vue-cli, in fact, you can achieve the front-end requirements, including node server, webpack, etc., so the extreme point: add axios is fine, koa2 is useless.

ask the boss to solve the problem, thank you.


1. The koa in the project you generate with vue-cli is only useful in the development environment, and the simulation of server, does not require koa
2 in the production environment. Generally speaking, projects with separation of front and rear ends rarely need to add a layer of node, between front-end and back-end java, that is, koa, unless, like Taobao, it needs to be optimized on the first screen or has strong seo requirements, and what needs to be requested by the browser is a static page that can be displayed directly, or the api provided by the back-end java cannot be directly displayed to the front end, and needs to be transformed. In order to need node middle layer
3.vue-router is front-end routing, is executed in the browser, url changes, switching different pages, while koa-router is mainly aimed at the server, for api routing


Koa is the same thing as express library, that is, a web service . It seems that it is rare to get data in Koa , and then render static html . After all, getting data is a time-consuming process. Now the usual practice is to load html, first and then request data asynchronously.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36044-40569.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36044-40569.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?