What is the difference between ViewModel and View,model in MVVM mode?
Model: Very simple, is the business logic-related data objects, usually from the database mapping, we can say that the database corresponding to the model.
View: Also very simple, is the display of the user interface.
Basically, most software does nothing more than read data from the data store, display it to the user interface, and then receive input from the user interface and write to the data store. So, for the data storage (model) and Interface (view) of the two layers, we have no objection to the basic. However, different people have different opinions on how to show the model to the view and how to write the data from view to model.
The MVC idea is that every change in the interface is an event, and I just need to write a bunch of code for each event to convert the user's input into the model object, which can be called a controller.
And the MVVM idea is that I give the view inside the various controls also define a corresponding data object, so that as long as the data object is modified, the contents of the view will automatically follow the refresh, and in the view to do anything, the data object is also automatically updated, so much the beautiful. So:
ViewModel: Is the model that corresponds to the interface (view). Because the database structure is often not directly corresponding to the interface control one by one, it is necessary to define a data object specifically corresponding to the control on the view. The role of ViewModel is to encapsulate the model object into an interface data object that can display and accept input.
As for the ViewModel data as the view is automatically refreshed and synced to the model, this part of the code can be written as a common framework, without the programmer to worry about.
Simply put, ViewModel is the connector for view and model, and the view and model implement two-way binding through ViewModel.
JS Architecture design Mode--MVVM mode, what is the difference between ViewModel and View,model