JS Architecture design Mode--MVVM mode, what is the difference between ViewModel and View,model

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.