First, layered architecture
The 1.Web app is divided into three layers: the behavioral layer, the data storage layer and the protocol layer, and the division of the layers is very clear.
A. The behavioral layer, embodied in the. Vue component and routing, holds some simple data that is primarily used to interact with users in a timely manner.
B. The data storage layer, reflected in the Vuex, the popular point is to store and process the requested data
C. The protocol layer is the acquisition of data (including requests and local access, etc.)
2. For three-layer direct base constraints
1. Data/function calls cannot span layers (except for functional interfaces, such as requests that have just entered the page)
2. Data processing should be done in the store
The 3.view layer can only do simple processing of the data in the store (e.g. data filtering for user-defined conditions)
4. Request written in the store action
5.websocket/server pushes data to be processed in the store (otherwise a memory leak may occur)
Second, the synchronous operation process
Question: Why can't I call the data in store directly?
Answer: Because state is updated in real time, mutations cannot perform asynchronous operations, and if you modify state directly, you can operate asynchronously, and when you operate asynchronously on the state, you are not done, and if the state has been modified elsewhere, This can cause problems with the program. So state to synchronize operations, by mutations the way to limit the asynchronous not allowed.
Iii. Asynchronous Operation Flow
Web App tiering Architecture (based on Vue+router+vuex)